Skip to content

Commit fc76913

Browse files
authored
Create Check If String Is a Prefix of Array.java
1 parent b85830e commit fc76913

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public boolean isPrefixString(String s, String[] words) {
3+
int idx = 0;
4+
for (String word : words) {
5+
for (int i = 0; i < word.length(); i++) {
6+
if (word.charAt(i) != s.charAt(idx)) {
7+
return false;
8+
}
9+
idx++;
10+
if (idx == s.length()) {
11+
return i == word.length() - 1;
12+
}
13+
}
14+
}
15+
return idx == s.length();
16+
}
17+
}

0 commit comments

Comments
 (0)