d******u 发帖数: 1142 | 1 多谢!
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 smaller than second, first << second, and you are
tasked with returning the largest expansion of first such that it is still a
subsequence of second. You can use the isSubsequence function from before
to help solve this problem. Let's also allow you to use a new get.
*/ | k****r 发帖数: 807 | 2 第二题简单吧,睡觉前写一下供参考:
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();
} | d******u 发帖数: 1142 | | s*a 发帖数: 267 | 4 第三问可以binary search, 设一个范围,expansion重复次数1到k,先试expansion重
复次数(1+k)/2的,如果这个串是子序列,move up,如果不是,move down | s*******e 发帖数: 207 | 5 same thought.
【在 s*a 的大作中提到】 : 第三问可以binary search, 设一个范围,expansion重复次数1到k,先试expansion重 : 复次数(1+k)/2的,如果这个串是子序列,move up,如果不是,move down
| l****u 发帖数: 1764 | 6 初始的k怎么取值呢?
【在 s*a 的大作中提到】 : 第三问可以binary search, 设一个范围,expansion重复次数1到k,先试expansion重 : 复次数(1+k)/2的,如果这个串是子序列,move up,如果不是,move down
| s*a 发帖数: 267 | 7 取为 ceiling(|S| / |s|)
S是长串,s是短串
【在 l****u 的大作中提到】 : 初始的k怎么取值呢?
|
|