Input: s = ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]
var reverseString = function (s) {
let left = 0;
let right = s.length - 1;
while (left < right) {
let temp = s[left]
s[left] = s[right]
s[right] = temp
left++
right--
}
};
3, 2, -1, -2, 3 3, 5, 4, 2, 5
var findMaxAverage = function (nums, k) {
let ans = 0
let sum = 0
for (let i = 0; i < k; i++) {
sum += nums[i]
}
ans = sum
for (let i = k; i < nums.length; i++) {
sum += nums[i] - nums[i - k]
ans = Math.max(sum, ans)
}
return ans / k
};
var sortedSquares = function(nums) {
let left = 0
let right = nums.length - 1
let ans = []
for (let i = nums.length - 1; i >= 0; i--) {
let leftVal = nums[left] * nums[left]
let rightVal = nums[right] * nums[right]
if (leftVal < rightVal) {
ans[i] = rightVal
right--
} else {
ans[i] = leftVal
left++
}
}
return ans
};
var longestOnes = function (nums, k) {
let ans = 0
let count = 0
let left = 0
for (let right = 0; right < nums.length; right++) {
if (nums[right] === 0) {
count++
}
if (count > k) {
if (nums[left] === 0) {
count--
}
left++
}
ans = Math.max(right - left + 1, ans)
}
return ans
};
var minStartValue = function (nums) {
let curr = nums[0]
let min = curr
for (let i = 1; i < nums.length; i++) {
curr += nums[i]
min = Math.min(curr, min)
}
return min < 0 ? Math.abs(min) + 1 : 1
};
var runningSum = function (nums) {
let sum = [nums[0]]
for (let i = 1; i < nums.length; i++) {
sum[i] = nums[i] + sum[i - 1]
}
return sum
};