35. searchInsert
var searchInsert = function(nums, target) {
nums.push(target)
nums.sort(function(a,b){
return a-b
})
return nums.indexOf(target)
};
38. countAndSay
语文题无法理解题意
53. maxSubArray
var maxSubArray = function(nums) {
var max = nums[0];
var sum = 0;
for (let x of nums) {
if (sum < 0) {
sum = 0;
}
sum += x;
max = Math.max(max, sum);
}
return max;
};
58. lengthOfLastWord
var lengthOfLastWord = function(s) {
var word = s.trim().split(" ")
return word[word.length-1].length
};
66. plusOne
var plusOne = function(digits) {
for(let i=digits.length-1;i>=0;i--){
if(digits[i] !== 9){
digits[i] = digits[i] + 1
return digits
}else{
digits[i] = 0
if(i === 0){
digits.unshift(1)
}
}
}
return digits
};
67. addBinary
不想做 →。→
69. mySqrt
var mySqrt = function(x) {
if(x===0){
return 0
}else{
return Math.sqrt(x)>=0 ? (Math.sqrt(x)-0.5).toFixed():(Math.sqrt(x)+0.5).toFixed()
}
};
70. climbStairs
不想做
83. deleteDuplicates
不会