c****s 发帖数: 241 | 1 write function to check whether two words are anagram or not.
do you have good solution for this problem? |
l*****a 发帖数: 14598 | 2 1)extra memory
str['a']..str['z']=0;
scan the first word,update array str.
scan the 2nd ,update str..
2)sort each word by itself,then string compare
3)assign the 1st ->26th prime number to 'a','b'...'z'
get the result of multiply each letter for each word
then compare.this may cause overflow
【在 c****s 的大作中提到】 : write function to check whether two words are anagram or not. : do you have good solution for this problem?
|
b******g 发帖数: 1721 | 3 collect letters to set1 from word1
collect letters to set2 from word2
if set1==set2, then anagram ; otherwise not. |
b******g 发帖数: 1721 | 4 open eyes.
【在 l*****a 的大作中提到】 : 1)extra memory : str['a']..str['z']=0; : scan the first word,update array str. : scan the 2nd ,update str.. : 2)sort each word by itself,then string compare : 3)assign the 1st ->26th prime number to 'a','b'...'z' : get the result of multiply each letter for each word : then compare.this may cause overflow
|
c****s 发帖数: 241 | 5 领教,领教。给你一个包子,请查收
【在 l*****a 的大作中提到】 : 1)extra memory : str['a']..str['z']=0; : scan the first word,update array str. : scan the 2nd ,update str.. : 2)sort each word by itself,then string compare : 3)assign the 1st ->26th prime number to 'a','b'...'z' : get the result of multiply each letter for each word : then compare.this may cause overflow
|
s********y 发帖数: 3811 | 6 u r so strong.
【在 l*****a 的大作中提到】 : 1)extra memory : str['a']..str['z']=0; : scan the first word,update array str. : scan the 2nd ,update str.. : 2)sort each word by itself,then string compare : 3)assign the 1st ->26th prime number to 'a','b'...'z' : get the result of multiply each letter for each word : then compare.this may cause overflow
|
l**u 发帖数: 368 | 7 这个可以归类为
就是所有的anagram都会映射到同一个key上去。
比如
dog
god
都能映射到dgo
【在 c****s 的大作中提到】 : write function to check whether two words are anagram or not. : do you have good solution for this problem?
|