File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @param {number } target
4
+ * @return {number }
5
+ */
6
+ var searchInsert = function ( nums , target ) {
7
+ let index = 0 ;
8
+ if ( nums [ nums . length - 1 ] < target ) {
9
+ return nums . length ;
10
+ }
11
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
12
+ if ( nums [ i ] === target || nums [ i ] > target ) {
13
+ index = i ;
14
+ break ;
15
+ }
16
+ }
17
+ return index ;
18
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @return {number }
4
+ */
5
+ var maxSubArray = function ( nums ) {
6
+ let res = nums [ 0 ] ;
7
+ let sum = 0 ;
8
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
9
+ if ( sum + nums [ i ] > nums [ i ] ) {
10
+ sum = sum + nums [ i ] ;
11
+ } else {
12
+ sum = nums [ i ] ;
13
+ }
14
+ res = Math . max ( res , sum ) ;
15
+ }
16
+ return res ;
17
+ } ;
Original file line number Diff line number Diff line change 1
1
Record LeetCode.
2
-
2
+ [ 53. 最大子序和] ( ./53-maximum-subarray.js )
3
+ [ 35. 搜索插入位置] ( ./35-search-insert-position.js )
3
4
[ 1512. 好数对的数目] ( ./1512-number-of-good-pairs.js )
4
5
[ 771. 宝石与石头] ( ./771-jewels-and-stones.js )
5
6
[ 82. 删除排序链表中的重复元素II] ( ./82-remove-duplicates-from-sorted-list-ii.js )
You can’t perform that action at this time.
0 commit comments