File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 34
34
| 37| [ 解数独] ( https://leetcode.cn/problems/sudoku-solver/ ) | [ JavaScript] ( ./algorithms/sudoku-solver.js ) | Hard|
35
35
| 39| [ 组合总和] ( https://leetcode.cn/problems/combination-sum/ ) | [ JavaScript] ( ./algorithms/combination-sum.js ) | Medium|
36
36
| 40| [ 组合总和 II] ( https://leetcode.cn/problems/combination-sum-ii/ ) | [ JavaScript] ( ./algorithms/combination-sum-ii.js ) | Medium|
37
+ | 45| [ 跳跃游戏 II] ( https://leetcode.cn/problems/jump-game-ii/ ) | [ JavaScript] ( ./algorithms/jump-game-ii.js ) | Medium|
37
38
| 46| [ 全排列] ( https://leetcode.cn/problems/permutations/ ) | [ JavaScript] ( ./algorithms/permutations.js ) | Medium|
38
39
| 47| [ 全排列 II] ( https://leetcode.cn/problems/permutations-ii/ ) | [ JavaScript] ( ./algorithms/permutations-ii.js ) | Medium|
39
40
| 48| [ 旋转图像] ( https://leetcode.cn/problems/rotate-image/ ) | [ JavaScript] ( ./algorithms/rotate-image.js ) | Medium|
192
193
| 977| [ 有序数组的平方] ( https://leetcode.cn/problems/squares-of-a-sorted-array/ ) | [ JavaScript] ( ./algorithms/squares-of-a-sorted-array.js ) | Easy|
193
194
| 988| [ 从叶结点开始的最小字符串] ( https://leetcode.cn/problems/smallest-string-starting-from-leaf/ ) | [ JavaScript] ( ./algorithms/smallest-string-starting-from-leaf.js ) | Medium|
194
195
| 1002| [ 查找共用字符] ( https://leetcode.cn/problems/find-common-characters/ ) | [ JavaScript] ( ./algorithms/find-common-characters.js ) | Easy|
196
+ | 1005| [ K 次取反后最大化的数组和] ( https://leetcode.cn/problems/maximize-sum-of-array-after-k-negations/ ) | [ JavaScript] ( ./algorithms/maximize-sum-of-array-after-k-negations.js ) | Easy|
195
197
| 1038| [ 从二叉搜索树到更大和树] ( https://leetcode.cn/problems/binary-search-tree-to-greater-sum-tree/ ) | [ JavaScript] ( ./algorithms/binary-search-tree-to-greater-sum-tree.js ) | Medium|
196
198
| 1047| [ 删除字符串中的所有相邻重复项] ( https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/ ) | [ JavaScript] ( ./algorithms/remove-all-adjacent-duplicates-in-string.js ) | Easy|
197
199
| 1233| [ 删除子文件夹] ( https://leetcode.cn/problems/remove-sub-folders-from-the-filesystem/ ) | [ JavaScript] ( ./algorithms/remove-sub-folders-from-the-filesystem.js ) | Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 45. 跳跃游戏 II
3
+ * @param {number[] } nums
4
+ * @return {number }
5
+ */
6
+ var jump = function ( nums ) {
7
+ if ( nums . length === 1 ) return 0 ;
8
+ let cover = nums [ 0 ] ;
9
+ let step = 0 ;
10
+ let reach = 0 ;
11
+
12
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
13
+ cover = Math . max ( i + nums [ i ] , cover ) ;
14
+ if ( cover >= nums . length - 1 ) {
15
+ return step + 1 ;
16
+ }
17
+ if ( i === reach ) {
18
+ step ++ ;
19
+ reach = cover ;
20
+ }
21
+ }
22
+ return step ;
23
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1005. K 次取反后最大化的数组和
3
+ * @param {number[] } nums
4
+ * @param {number } k
5
+ * @return {number }
6
+ */
7
+ var largestSumAfterKNegations = function ( nums , k ) {
8
+ let sum = 0 ;
9
+ nums . sort ( ( a , b ) => Math . abs ( b ) - Math . abs ( a ) ) ;
10
+
11
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
12
+ if ( nums [ i ] < 0 && k > 0 ) {
13
+ nums [ i ] = - nums [ i ] ;
14
+ k -- ;
15
+ }
16
+ }
17
+ if ( k > 0 && k % 2 === 1 ) {
18
+ nums [ nums . length - 1 ] *= - 1 ;
19
+ }
20
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
21
+ sum += nums [ i ] ;
22
+ }
23
+
24
+ return sum ;
25
+ } ;
You can’t perform that action at this time.
0 commit comments