k**8 发帖数: 186 | 1 1. talk about your projects (more details were asked)
2. whats BST
3. how to implement BST(more specific details here)
4. how to identify an integer is a power of 2
5. Sort string a based on the order of the letters in string b.
For example: a = cat, b = tar, sorted = tac
All above took about 1 hour. |
g***j 发帖数: 1275 | 2 最后一题怎么回答的啊?
可以不可以搞一个map,把字母和数字重新对应?
t - 1
a - 2
r - 3
然后 cat 就是421 排序之后,就是 124,然后再映射回来,就是tac啦?
【在 k**8 的大作中提到】 : 1. talk about your projects (more details were asked) : 2. whats BST : 3. how to implement BST(more specific details here) : 4. how to identify an integer is a power of 2 : 5. Sort string a based on the order of the letters in string b. : For example: a = cat, b = tar, sorted = tac : All above took about 1 hour.
|
j*****s 发帖数: 189 | 3 怎么得到phone interview的机会的?求指导啊。
【在 k**8 的大作中提到】 : 1. talk about your projects (more details were asked) : 2. whats BST : 3. how to implement BST(more specific details here) : 4. how to identify an integer is a power of 2 : 5. Sort string a based on the order of the letters in string b. : For example: a = cat, b = tar, sorted = tac : All above took about 1 hour.
|
p*****2 发帖数: 21240 | 4
写一个comparator就可以了吧?
【在 g***j 的大作中提到】 : 最后一题怎么回答的啊? : 可以不可以搞一个map,把字母和数字重新对应? : t - 1 : a - 2 : r - 3 : 然后 cat 就是421 排序之后,就是 124,然后再映射回来,就是tac啦?
|
g***j 发帖数: 1275 | 5 是的
但是comparator里面如何定义俩字母的相对大小呢?
【在 p*****2 的大作中提到】 : : 写一个comparator就可以了吧?
|
r*****i 发帖数: 26 | 6 确实要搞个map,把字母映射到出现的位置,然后再用comparator就可以了。问题是如
果a和b不同字母的个数多于一个的话,这种映射是不是会有二义性啊?
【在 g***j 的大作中提到】 : 是的 : 但是comparator里面如何定义俩字母的相对大小呢?
|
e****e 发帖数: 418 | 7 IMHO, the limitation of this question is b shouldn't have dups.
public String sort(String input, String order) {
Map map = new LinkedHashMap(
);
for ( int i = 0; i < order.length(); i++ )
map.put( order.charAt( i ), 0 );
for ( int i = 0; i < input.length(); i++ ) {
char c = input.charAt( i );
if ( map.containsKey( c ) )
map.put( c , map.get(c) + 1 );
else
map.put( c , 1 );
}
StringBuffer sb = new StringBuffer();
for ( Map.Entry entry : map.entrySet() ) {
for ( int i = 0; i < entry.getValue(); i++ )
sb.append( entry.getKey() );
}
return sb.toString();
}
【在 r*****i 的大作中提到】 : 确实要搞个map,把字母映射到出现的位置,然后再用comparator就可以了。问题是如 : 果a和b不同字母的个数多于一个的话,这种映射是不是会有二义性啊?
|
k****r 发帖数: 807 | |
F********9 发帖数: 44 | 9 comparator, 加个构造函数参数。
char array[26] = {0};
i = 0;
for c in str:
array[c] = ++i;
重载operator(),直接查值就行了,不用散列那么麻烦。
【在 r*****i 的大作中提到】 : 确实要搞个map,把字母映射到出现的位置,然后再用comparator就可以了。问题是如 : 果a和b不同字母的个数多于一个的话,这种映射是不是会有二义性啊?
|
c**m 发帖数: 535 | |
l*****a 发帖数: 14598 | 11 顺序怎么定的,没看懂
另外如果支持大小写怎么办,支持unicode怎么办?支持无穷大字符集怎么办?
【在 F********9 的大作中提到】 : comparator, 加个构造函数参数。 : char array[26] = {0}; : i = 0; : for c in str: : array[c] = ++i; : 重载operator(),直接查值就行了,不用散列那么麻烦。
|
d**s 发帖数: 98 | 12 Thanks!
【在 k**8 的大作中提到】 : 1. talk about your projects (more details were asked) : 2. whats BST : 3. how to implement BST(more specific details here) : 4. how to identify an integer is a power of 2 : 5. Sort string a based on the order of the letters in string b. : For example: a = cat, b = tar, sorted = tac : All above took about 1 hour.
|