题解 | #寻找连续任务开始位置#
寻找连续任务开始位置
https://www.nowcoder.com/practice/c93fd6c526da40788fd832ef9cd7177e
知识点
字符串
解题思路
words中的单词都是有序出现在s中的,这道题就只需要将words中的单词拼接起来,运用indexOf找到第一次出现的下标即可。
Java题解
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @param words string字符串一维数组
* @return int整型
*/
public int findLongestSubstring (String s, String[] words) {
// write code here
String s2 = "";
for(int i=0;i<words.length;i++){
s2+=words[i];
}
return s.indexOf(s2);
}
}
查看20道真题和解析
