https://leetcode.com/problems/remove-element/
回傳不等於目標值外的長度。
利用for迴圈判斷陣列值是否符合目標值,不是的話可以放到另一個陣列或用一個變數記錄其長度回傳。
int removeElement(int* nums, int numsSize, int val) {
int m=0;
for(int i=0; i<numsSize; i++)
{
if(nums[i] != val)
{
nums[m] = nums[i];
m++;
}
}
return m;
}
var removeElement = function(nums, val) {
var temp = [];
for(var i = 0; i<nums.length; i++)
{
if(nums[i] != val)
temp.push(nums[i]);
}
return temp.length;
};
https://github.com/SIAOYUCHEN/leetcode
https://ithelp.ithome.com.tw/users/20100009/ironman/2500
https://ithelp.ithome.com.tw/users/20113393/ironman/2169
https://ithelp.ithome.com.tw/users/20107480/ironman/2435
https://ithelp.ithome.com.tw/users/20107195/ironman/2382
https://ithelp.ithome.com.tw/users/20119871/ironman/2210
https://ithelp.ithome.com.tw/users/20106426/ironman/2136
Walk a different path, and you will see a different sight.
沒走過的路,才能看到沒看過的風景