摘要: 题目 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。 说明: 为什么返回数值是整数,但 阅读全文
posted @ 2021-12-17 17:51 宗神一 阅读(24) 评论(0) 推荐(0) 编辑
摘要: 题目 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 示例: 输入: [0,1,0,3,12]输出: [1,3,12,0,0]说明: 必须在原数组上操作,不能拷贝额外的数组。尽量减少操作次数。 来源:力扣(LeetCode)链接:https://lee 阅读全文
posted @ 2021-12-17 16:14 宗神一 阅读(25) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/max-consecutive-ones/ 我的题解: class Solution { public int findMaxConsecutiveOnes(int[] nums) { int max = 0; int cu 阅读全文
posted @ 2021-12-17 12:18 宗神一 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 题目地址:https://leetcode-cn.com/problems/water-bottles/ 我的答案: class Solution { public int numWaterBottles(int numBottles, int numExchange) { /** numBottl 阅读全文
posted @ 2021-12-17 12:15 宗神一 阅读(17) 评论(0) 推荐(0) 编辑