class Solution public void moveZeroesvectorint& nums int naught=0; forauto it=numsbegin;it!=numsend;it++ if!it numseraseit--naught++; whilenaught-- numsemplace_back0; ;改成Swift
class Solution { func moveZeroes(_ nums: inout [Int]) { var naught = 0 var index = 0 while index < nums.count - naught { if nums[index] == 0 { nums.remove(at: index) naught += 1 } else { index += 1 } } nums += Array(repeating: 0, count: naught) } }
原文地址: https://www.cveoy.top/t/topic/itHF 著作权归作者所有。请勿转载和采集!