varremoveElement=function(nums, val){const n = nums.length;let left =0;for(let right =0; right < n; right++){if(nums[right]!== val){
nums[left]= nums[right];
left++;}}return left;};
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/varbackspaceCompare=function(S,T){let i =S.length -1,
j =T.length -1,
skipS =0,
skipT =0;//大循环while(i >=0|| j >=0){// S 循环while(i >=0){if(S[i]==='#'){
skipS++;
i--;}elseif(skipS >0){
skipS--;
i--;}elsebreak;}// T 循环while(j >=0){if(T[j]==='#'){
skipT++;
j--;}elseif(skipT >0){
skipT--;
j--;}elsebreak;}if(S[i]!==T[j])returnfalse;
i--;
j--;}returntrue;};
有序数组的平方(leetcode977)
/**
* @param {number[]} nums
* @return {number[]}
*/varsortedSquares=function(nums){const n = nums.length;const ans =Array(n);let i =0, j = n -1;for(let p = n -1; p >=0; p--){const x = nums[i]* nums[i];const y = nums[j]* nums[j];if(x > y){
ans[p]= x;
i++;}else{
ans[p]= y;
j--;}}return ans;};