【发布时间】:2017-10-20 20:50:03
【问题描述】:
char first = target[targetOffset];
int max = sourceOffset + (sourceCount - targetCount);
for (int i = sourceOffset + fromIndex; i <= max; i++) {
/* Look for first character. */
if (source[i] != first) {
while (++i <= max && source[i] != first);
}
/* Found first character, now look at the rest of v2 */
if (i <= max) {
int j = i + 1;
int end = j + targetCount - 1;
for (int k = targetOffset + 1; j < end && source[j] ==
target[k]; j++, k++);
if (j == end) {
/* Found whole string. */
return i - sourceOffset;
}
}
【问题讨论】:
-
不,只要最小的数字在最大的数字之前,我试图获得值之间的最大差异。
max行不通,因为价格从最高数字开始?我不知道如何比较数组中的值? -
最大利润应该是在 11 时做空并在 1 时补仓。;-) 看起来像 reduce 的工作。
-
@jfriend00 编辑了问题以删除效率 - 让我知道这是否足够如果您不同意,我将关闭 q!
-
我认为这个问题与
.indexOf()没有任何关系,您的标题似乎表明您认为您必须使用它。这是需要使用.indexOf()的作业题吗? -
@jfriend00 哈哈,我没有作业..
标签: javascript algorithm ecmascript-6