File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number } n
3+ * @return {number }
4+ */
5+ var climbStairs = function ( n ) {
6+ const memo = { } ;
7+
8+ function fibo ( num , memo ) {
9+ if ( num === 1 ) return 1 ;
10+ if ( num === 2 ) return 2 ;
11+
12+ if ( memo [ num ] ) {
13+ return memo [ num ] ;
14+ }
15+
16+ const result = fibo ( num - 1 , memo ) + fibo ( num - 2 , memo ) ;
17+ memo [ num ] = result ;
18+
19+ return result ;
20+ }
21+
22+ return fibo ( n , memo ) ;
23+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } s
3+ * @param {string } t
4+ * @return {boolean }
5+ */
6+ var isAnagram = function ( s , t ) {
7+ const stringMap = new Map ( ) ;
8+
9+ if ( s . length !== t . length ) return false ;
10+
11+ for ( let i = 0 ; i < s . length ; i ++ ) {
12+ const currentValue = stringMap . get ( s [ i ] ) ;
13+
14+ if ( currentValue ) {
15+ stringMap . set ( s [ i ] , currentValue + 1 ) ;
16+ } else {
17+ stringMap . set ( s [ i ] , 1 ) ;
18+ }
19+ }
20+
21+ for ( let i = 0 ; i < t . length ; i ++ ) {
22+ const currentValue = t [ i ] ;
23+ const currentValueInStringMap = stringMap . get ( currentValue ) ;
24+
25+ if ( currentValueInStringMap ) {
26+ stringMap . set ( currentValue , currentValueInStringMap - 1 ) ;
27+ } else {
28+ return false ;
29+ }
30+ }
31+
32+ return true ;
33+ } ;
You can’t perform that action at this time.
0 commit comments