LeetCode 242 Valid an (effective crossword )(*)

Source: Internet
Author: User

LeetCode 242 Valid an (effective crossword )(*)
Translation

Given two strings s and t, write a function to determine whether t is a word of s. For example, s = "ansible", t = "nagaram", returns trues = "rat", t = "car", and returns false. Note: you can assume that the string contains only lowercase letters. Follow-up: What should I do if the input contains unicode characters? Can your solution adapt to this situation?
Original
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may assume the string contains only lowercase alphabets.Follow up:What if the inputs contain unicode characters? How would you adapt your solution to such case?
Analysis

It can be written in almost seconds, but I'm not sure whether unicode in the question can be used ...... Because I don't know how to input this ...... Try again later.

#include 
  
   #include using namespace std;bool isAnagram(string s, string t) {    sort(s.begin(), s.end());    sort(t.begin(), t.end());    return s == t;}int main() {        string s = "anagram";    string t = "nagaram";    cout << isAnagram(s, t);    return 0;}
  

At the beginning, I saw that the translation gave a "Word Puzzle". I don't understand the meaning of the question. Is it a riddle? And the other string is the answer? There is no word library in the program, how to write ...... Then I checked the word "nagaram", which does not exist.

Code
class Solution {public:    bool isAnagram(string s, string t) {        sort(s.begin(), s.end());        sort(t.begin(), t.end());        return s == t;    }};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.