File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
two-sum-iii-data-structure-design Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/two-sum-iii-data-structure-design/
49
+
48
50
https://leetcode.cn/problems/minimum-adjacent-swaps-for-k-consecutive-ones
49
51
50
52
https://leetcode.cn/problems/form-array-by-concatenating-subarrays-of-another-array/
Original file line number Diff line number Diff line change
1
+ export default class TwoSum {
2
+ #m = new Map < number , number > ( ) ;
3
+
4
+ add ( n : number ) {
5
+ this . #m. set ( n , ( this . #m. get ( n ) ?? 0 ) + 1 ) ;
6
+ }
7
+ find ( n : number ) {
8
+ for ( const [ a , cnt ] of this . #m) {
9
+ const b = n - a ;
10
+ if ( a > b ) return false ;
11
+ if ( a === b ) return cnt > 1 ;
12
+
13
+ if ( this . #m. has ( b ) ) return true ;
14
+ }
15
+ return false ;
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments