8000 String · Ibhrahimazzad/LeetcodeMay@a43562e · GitHub
[go: up one dir, main page]

Skip to content

Commit a43562e

Browse files
String
1 parent 622ac17 commit a43562e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

WEEK 1/Question 3 Ransom Note.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
bool canConstruct(string ransomNote, string magazine) {
4+
int a[30]={0};
5+
for(char ch: magazine)
6+
{
7+
a[ch-97]++;
8+
}
9+
for(char ch: ransomNote)
10+
{
11+
if(a[ch-97]<=0)return false;
12+
if(a[ch-97]>0)a[ch-97]--;
13+
}
14+
return true;
15+
}
16+
};

0 commit comments

Comments
 (0)
0