forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_383.java
More file actions
24 lines (20 loc) · 676 Bytes
/
_383.java
File metadata and controls
24 lines (20 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.fishercoder.solutions;
public class _383 {
public static class Solution1 {
public boolean canConstruct(String ransomNote, String magazine) {
char[] mchars = magazine.toCharArray();
int[] mcnt = new int[256];
for (int i = 0; i < mchars.length; i++) {
mcnt[mchars[i] - 'a']++;
}
char[] rchars = ransomNote.toCharArray();
for (int i = 0; i < rchars.length; i++) {
if (mcnt[rchars[i] - 'a'] <= 0) {
return false;
}
mcnt[rchars[i] - 'a']--;
}
return true;
}
}
}