283. Move Zeroes--LeetCode Record
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].
func moveZeroes(inout nums: [Int]) {
var zeroCount:Int = 0
for index in 0..<nums.count {
if nums[index] == 0 {
zeroCount++
continue
}
swap(&nums, index, index - zeroCount)
}
}
func swap(inout nums: [Int], _ p:Int , _ q:Int) {
if p <= (nums.count - 1) && q <= (nums.count - 1) {
var num:Int = nums[q]
nums[q] = nums[p]
nums[p] = num
}
}
相關文章
- 283. 移動零
- 力扣-283. 移動零力扣
- WPF mvvm canvas move elements via mouse down, up and move eventsMVVMCanvas
- leetcode 283. 移動零(簡單)LeetCode
- LeetCode—283—Move ZeroesLeetCode
- react-recordReact
- Active Record Associations
- screen-record
- oracle 分割槽表move和包含分割槽表的lob moveOracle
- WPF Image zoomin zoomout moveOOM
- ES6+ ---- record
- Daily record-SeptemberAI
- Learn and Record12
- Camera List Record - 120
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- alter table move與shrink space
- Office365 OneDrive Geo Move
- 12C 線上MOVE
- Travel Notes-Record mood
- Homework record-Simple sorting
- SAP Move to Rise是什麼意思? SAP Move的五條路徑是什麼?
- leetcode陣列練習題2:283. 移動零LeetCode陣列
- 每週一算:Move ZerosROS
- C++ 逆向之 move 函式C++函式
- BULK In-BIND與RECORD(轉)
- Renovation Tour-Record my home
- Java 21 新特性:Record PatternsJava
- Record It for Mac錄屏軟體Mac
- gorm忽略報錯: record not foundGoORM
- Java 16 新特性:record類Java
- Erlang中的Record詳解
- 淺析 record 使用場景
- how to move a MediaWiki wiki from one server to anotherServer
- Lintcode539 Move Zeroes solution 題解
- record:記錄(帶名元組)
- 不好分類的好題Record
- PerconaXtraDBClusterGCache和Record-Set快取GC快取
- Oracle move和shrink釋放高水位空間Oracle
- move linux os from disk A to disk B with 0 lossLinux