File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ Step 2. Add the dependency
49
49
50
50
<summary >展开查看</summary >
51
51
52
+ https://leetcode.cn/problems/ransom-note
53
+
52
54
https://leetcode.cn/problems/valid-perfect-square
53
55
54
56
https://leetcode.cn/problems/insufficient-nodes-in-root-to-leaf-paths
Original file line number Diff line number Diff line change
1
+ module ;
2
+ #include < unordered_map>
3
+ #include < string>
4
+ export module ransom_note.Solution;
5
+ namespace ransom_note
6
+ {
7
+ using std::string;
8
+ using std::unordered_map;
9
+ export class Solution
10
+ {
11
+
12
+ public:
13
+ bool canConstruct (string ransomNote, string magazine)
14
+ {
15
+
16
+ auto map1 = unordered_map<char , int >{};
17
+
18
+ for (auto c : magazine)
19
+ {
20
+ map1[c]++;
21
+ }
22
+
23
+ for (auto c : ransomNote)
24
+ {
25
+ map1[c]--;
26
+ if (map1[c] < 0 )
27
+ return false ;
28
+ }
29
+ return true ;
30
+ }
31
+ };
32
+
33
+ }
Original file line number Diff line number Diff line change
1
+ export default function canConstruct (
2
+ ransomNote : string ,
3
+ magazine : string ,
4
+ ) : boolean {
5
+ const map1 = new Map < string , number > ( ) ;
6
+
7
+ for ( const c of magazine ) {
8
+ map1 . set ( c , 1 + ( ( map1 . get ( c ) ) ?? 0 ) ) ;
9
+ }
10
+
11
+ for ( const c of ransomNote ) {
12
+ map1 . set ( c , - 1 + ( ( map1 . get ( c ) ) ?? 0 ) ) ;
13
+
14
+ if ( ( ( map1 . get ( c ) ) ?? 0 ) < 0 ) return false ;
15
+ }
16
+ return true ;
17
+ }
You can’t perform that action at this time.
0 commit comments