题解 | #寻找连续任务开始位置#

寻找连续任务开始位置

https://www.nowcoder.com/practice/c93fd6c526da40788fd832ef9cd7177e

题目考察的知识点

考察字符串操作

题目解答方法的文字分析

根据题意其实就是在主串中查找words中字符串的出现位置,所以拼接word字符串后直接调用API查找即可

本题解析所用的编程语言

使用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 p = "";
        for (int i = 0; i < words.length; i++) {
            p += words[i];
        }
        return s.indexOf(p, 0);
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务