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. 移動零力扣
- Move to GithubGithub
- leetcode 283. 移動零(簡單)LeetCode
- move.jsJS
- react-recordReact
- Oracle的move操作Oracle
- move表操作流程
- move oracle 10 directoryOracle
- Daily record-SeptemberAI
- oracle 分割槽表move和包含分割槽表的lob moveOracle
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- Move_or_Rename_the_Tempfile_in_OracleOracle
- CopyMemory Move使用筆記筆記
- ORACLE MOVE表空間Oracle
- Move users between domainsAI
- pl/sql record 詳解SQL
- delete duplication record in sql serverdeleteSQLServer
- leetcode陣列練習題2:283. 移動零LeetCode陣列
- alter table table_name move ; 在自身表空間move是如何操作的?
- LeetCode—283—Move ZeroesLeetCode
- Move datafile:From File System to ASMASM
- Move datafile:From ASM to File SystemASM
- How to move progress database to different OSDatabase
- Java 16 新特性:record類Java
- Erlang中的Record詳解
- 淺析 record 使用場景
- Record It for Mac錄屏軟體Mac
- Java 21 新特性:Record PatternsJava
- 脫離rails 使用Active RecordAI
- Homework record-Simple sorting
- gorm忽略報錯: record not foundGoORM
- 每週一算:Move ZerosROS
- How To Move The DB Audit Trails To A New TablespaceAI
- [轉移]ORACLE MOVE 表空間Oracle
- 批量move tablespace 指令碼範例指令碼
- table move 與 shrink 的區別
- ALTER TABLE MOVE | SHRINK SPACE區別
- [Oracle] Shrink space & Table move比較Oracle