1 public int removeElement(int[] nums, int val) { 2 int last = nums.length - 1; 3 for (int i = 0; i <= last && last >= 0; i++) { 4 while (last >= 0 && nums[last] == val) last--; 5 if (last >= 0 && i < last && nums[i] == val) { 6 nums[i] = nums[last]; 7 last--; 8 } 9 } 10 return last + 1; 11 }
原文地址:https://www.cnblogs.com/towerbird/p/11614345.html
时间: 2024-11-07 07:40:15