当前位置:网站首页>Leetcode1961. Check whether the string is an array prefix

Leetcode1961. Check whether the string is an array prefix

2022-07-06 01:16:00 May Hacker

https://leetcode.cn/problems/check-if-string-is-a-prefix-of-array/

Java AC

class Solution {
    
    public boolean isPrefixString(String s, String[] words) {
    
        int index = 0;
        for(int i=0;i<words.length;i++){
    
            String str = words[i];
            for(int j=0;j<str.length();j++){
    
                if(index>=s.length() || str.charAt(j)!=s.charAt(index++)){
    
                    return false;
                }

            }
            if(index==s.length()){
    
                return true;
            }
        }
        return false;
    }
}
原网站

版权声明
本文为[May Hacker]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060110194646.html