Skip to content

Commit bc9803f

Browse files
Create 1160-Find-Words-That-Can-Be-Formed-by-Characters.java
1 parent 9529cb2 commit bc9803f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//Intuitive approach
2+
3+
class Solution {
4+
public int countCharacters(String[] words, String chars) {
5+
int[] arrChars = new int[26];
6+
for (int i = 0; i<chars.length(); i++) {
7+
arrChars[chars.charAt(i)-'a']++;
8+
}
9+
int ans = 0;
10+
for (String s: words) {
11+
boolean flag = true;
12+
int[] arrS = new int[26];
13+
for (int i= 0; i<s.length(); i++) {
14+
arrS[s.charAt(i)-'a']++;
15+
}
16+
for (int i =0; i<26; i++) {
17+
if (arrS[i]>arrChars[i])
18+
flag = false;
19+
}
20+
if (flag) ans += s.length();
21+
}
22+
return ans;
23+
}
24+
}

0 commit comments

Comments
 (0)