由买买提看人间百态

topics

全部话题 - 话题: toexpand
(共0页)
d******u
发帖数: 1142
1
来自主题: JobHunting版 - 请教一道面试题
多谢!
http://www.1point3acres.com/bbs/thread-205852-1-1.html
bool isSubsequence(string first, string second);
判断第一个字符串是不是第二个的subsequence
string getExpansion(string toExpand, int expansion);
// getExpansion takes a string toExpand and duplicates each char in place
// EX: "abc", 2
// "aabbcc". from: 1point3acres.com/bbs
// EX: "abc", 1
// "abc"
// EX: "abc", 0
// EX: "aabbcc", 2
// "aaaabbbbcccc"
/*
3.Imagine the following problem, you are given two strings, first and second
, where first is much s... 阅读全帖
k****r
发帖数: 807
2
来自主题: JobHunting版 - 请教一道面试题
第二题简单吧,睡觉前写一下供参考:
public String getExpansion(String toExpand, int expansion) {
char[] chs = toExpand.toCharArray();
StringBuilder sb = new StringBuilder();
if (expansion > 0) {
for (char c : chs) {
for (int i = 0; i < expansion; i++) {
sb.append(c);
}
}
}
return sb.toString();
}
(共0页)