C语言 | Leetcode C语言题解之第283题移动零

题目:

题解:

cpp 复制代码
void swap(int *a, int *b) {
    int t = *a;
    *a = *b, *b = t;
}

void moveZeroes(int *nums, int numsSize) {
    int left = 0, right = 0;
    while (right < numsSize) {
        if (nums[right]) {
            swap(nums + left, nums + right);
            left++;
        }
        right++;
    }
}
相关推荐
学逆向的8 小时前
C 循环结构的执行效率分析
c语言·开发语言·数据结构·网络安全
Navigator_Z11 小时前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
Nil20812 小时前
leetcode 64最小路径和
算法·leetcode·职场和发展
jeo陽12 小时前
04-循环实战:素数、最大公约数、级数求和与枚举法
c语言·开发语言·数据结构
Nil20812 小时前
leetcode 72编辑距离
算法·leetcode·职场和发展
Nil20813 小时前
leetcode 136只出现一次的数字
leetcode·哈希算法·散列表
lvwangshu14 小时前
川剧复演 题解
动态规划·题解·技巧·性质题·思维好题
爱读书的小胖14 小时前
LeetCode 88. 合并两个有序数组 C 解题分析
c语言·数据结构·算法
inrichtt15 小时前
第七课时:STM32时钟系统揭秘:从零理解时钟树
c语言·数据结构·stm32·单片机·嵌入式硬件
知识分享小能手15 小时前
C学习教程,从入门到精通,C语言指针 —— 详细知识点总结(10)
c语言·开发语言·学习