File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ const cache : number [ ] = [ ] ;
2+
3+ function climbStairs ( n : number ) : number {
4+ if ( n === 1 ) return 1
5+ if ( n === 2 ) return 2 ;
6+
7+ // cache κ° μμ λ
8+ if ( cache [ n ] ) return cache [ n ]
9+
10+ // cache κ° μμ λ
11+ cache [ n ] = climbStairs ( n - 1 ) + climbStairs ( n - 2 ) ;
12+ return cache [ n ]
13+ } ;
Original file line number Diff line number Diff line change 1+ function isAnagram ( s : string , t : string ) : boolean {
2+ let sObj = { }
3+ let tObj = { }
4+
5+ s . split ( '' ) . sort ( ) . map ( ( sChar ) => {
6+ if ( sChar in sObj ) {
7+ sObj [ sChar ] += 1
8+ } else {
9+ sObj [ sChar ] = 1
10+ }
11+ } )
12+
13+ t . split ( '' ) . sort ( ) . map ( ( tChar ) => {
14+ if ( tChar in tObj ) {
15+ tObj [ tChar ] += 1
16+ } else {
17+ tObj [ tChar ] = 1
18+ }
19+ } )
20+
21+ return JSON . stringify ( sObj ) === JSON . stringify ( tObj )
22+ } ;
You canβt perform that action at this time.
0 commit comments