We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Descripe
Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Input: s = "anagram", t = "nagaram" Output: true
Example 2:
Input: s = "rat", t = "car" Output: 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?
解题思路:使用哈希表,声明一个26长度的数组,初始值为0,字母每重复一次+1
C解题:
bool isAnagram(char * s, char * t){ int len_s = strlen(s); int len_t = strlen(t); if (len_s != len_t) return false; int map[26] = {0}; for(int i = 0;i<len_s;i++) ++map[s[i] - 'a']; for(int i = 0;i<len_t;i++){ if (--map[t[i] - 'a'] < 0) return false; } return true; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Descripe
Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Example 2:
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?
解题思路:使用哈希表,声明一个26长度的数组,初始值为0,字母每重复一次+1
C解题:
The text was updated successfully, but these errors were encountered: