From 8589ae546b84ed150d88b31f663c378e47a6ff79 Mon Sep 17 00:00:00 2001 From: Joshua <47053655+Joshua-Lu@users.noreply.github.com> Date: Thu, 13 May 2021 22:50:47 +0800 Subject: [PATCH] =?UTF-8?q?Update=200027.=E7=A7=BB=E9=99=A4=E5=85=83?= =?UTF-8?q?=E7=B4=A0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 0027.移除元素 Java版本 --- problems/0027.移除元素.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/problems/0027.移除元素.md b/problems/0027.移除元素.md index 959474fc..aab174cf 100644 --- a/problems/0027.移除元素.md +++ b/problems/0027.移除元素.md @@ -123,6 +123,22 @@ public: Java: +```java +class Solution { + public int removeElement(int[] nums, int val) { + // 快慢指针 + int fastIndex = 0; + int slowIndex; + for (slowIndex = 0; fastIndex < nums.length; fastIndex++) { + if (nums[fastIndex] != val) { + nums[slowIndex] = nums[fastIndex]; + slowIndex++; + } + } + return slowIndex; + } +} +``` Python: @@ -172,4 +188,4 @@ var removeElement = (nums, val) => { * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
\ No newline at end of file +