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; }};