8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e459548 commit 4811123Copy full SHA for 4811123
May-LeetCoding-Challenge/03-Ransom-Note/Ransom-Note.cs
@@ -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
27
28
+ return false;
29
30
31
32
+ return true;
33
34
+}
0 commit comments