Skip to content

Commit

Permalink
✨ feat: 53 && 35;
Browse files Browse the repository at this point in the history
  • Loading branch information
ConteMan committed Jun 25, 2021
1 parent f533a9e commit 2f81c69
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
18 changes: 18 additions & 0 deletions 35-search-insert-position.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
var searchInsert = function(nums, target) {
let index = 0;
if (nums[nums.length - 1] < target) {
return nums.length;
}
for (let i = 0; i < nums.length; i++) {
if (nums[i] === target || nums[i] > target) {
index = i;
break;
}
}
return index;
};
17 changes: 17 additions & 0 deletions 53-maximum-subarray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {number[]} nums
* @return {number}
*/
var maxSubArray = function(nums) {
let res = nums[0];
let sum = 0;
for (let i = 0; i < nums.length; i++) {
if (sum + nums[i] > nums[i]) {
sum = sum + nums[i];
} else {
sum = nums[i];
}
res = Math.max(res, sum);
}
return res;
};
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Record LeetCode.

[53. 最大子序和](./53-maximum-subarray.js)
[35. 搜索插入位置](./35-search-insert-position.js)
[1512. 好数对的数目](./1512-number-of-good-pairs.js)
[771. 宝石与石头](./771-jewels-and-stones.js)
[82. 删除排序链表中的重复元素II](./82-remove-duplicates-from-sorted-list-ii.js)
Expand Down

0 comments on commit 2f81c69

Please sign in to comment.