From 966ccbe6314c401fa9a4fc988bdd90a16cec2975 Mon Sep 17 00:00:00 2001 From: Zong <1003160664@qq.com> Date: Thu, 13 Aug 2020 19:34:34 +0800 Subject: [PATCH] =?UTF-8?q?Update=20LeetCode=E7=AC=AC283=E5=8F=B7=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9A=E7=A7=BB=E5=8A=A8=E9=9B=B6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加Java、Python语言支持 --- notes/LeetCode第283号问题:移动零.md | 44 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/notes/LeetCode第283号问题:移动零.md b/notes/LeetCode第283号问题:移动零.md index d77ab91..352a9a2 100644 --- a/notes/LeetCode第283号问题:移动零.md +++ b/notes/LeetCode第283号问题:移动零.md @@ -103,8 +103,9 @@ public: ![](https://blog-1257126549.cos.ap-guangzhou.myqcloud.com/blog/gcetr.gif) 代码如下: +C++ Code: -``` +```c++ // 原地(in place)解决该问题 // 时间复杂度: O(n) // 空间复杂度: O(1) @@ -130,8 +131,45 @@ public: ``` +Java Code: + +```java +class Solution { + public void moveZeroes(int[] nums) { + // 双指针 + int i = 0; + for(int j=0; j None: + """ + Do not return anything, modify nums in-place instead. + """ + # 双指针 + i = 0 + for j in range(len(nums)): + # 不为0,前移 + if nums[j] != 0: + nums[i], nums[j] = nums[j], nums[i] + i+=1 +``` - -![](https://blog-1257126549.cos.ap-guangzhou.myqcloud.com/blog/o6der.png) \ No newline at end of file +![](https://blog-1257126549.cos.ap-guangzhou.myqcloud.com/blog/o6der.png)