8000 corret filepath · qilingit/Leetcode@4811123 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4811123

Browse files
committed
corret filepath
1 parent e459548 commit 4811123

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
public class Solution {
2+
public bool CanConstruct(string ransomNote, string magazine) {
3+
4+
Dictionary<char, int> dicMagazine = new Dictionary<char, int>();
5+
foreach (char c in magazine)
6+
{
7+
if(dicMagazine.ContainsKey(c))
8+
{
9+
dicMagazine[c] ++;
10+
}
11+
else
12+
{
13+
dicMagazine.Add(c,1);
14+
}
15+
}
16+
foreach (char r in ransomNote)
17+
{
18+
if (dicMagazine.ContainsKey(r))
19+
{
20+
dicMagazine[r] --;
21+
if ( dicMagazine[r] == 0)
22+
{
23+
dicMagazine.Remove(r);
24+
}
25+
}
26+
else
27+
{
28+
return false;
29+
}
30+
31+
}
32+
return true;
33+
}
34+
}

0 commit comments

Comments
 (0)
0