From f5da40eb54233be18e63583cad68ed8298f2752e Mon Sep 17 00:00:00 2001 From: lucifer Date: Mon, 26 Apr 2021 14:48:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(ml):=20leetcode27=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=83=E7=B4=A0=20=E6=B7=BB=E5=8A=A0=20Python3=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- animation-simulation/数组篇/leetcode27移除元素.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/animation-simulation/数组篇/leetcode27移除元素.md b/animation-simulation/数组篇/leetcode27移除元素.md index 015b504..a7a51b8 100644 --- a/animation-simulation/数组篇/leetcode27移除元素.md +++ b/animation-simulation/数组篇/leetcode27移除元素.md @@ -85,6 +85,8 @@ class Solution { **题目代码:** +Java Code: + ```java class Solution { public int removeElement(int[] nums, int val) { @@ -106,3 +108,16 @@ class Solution { } ``` +Python3 Code: + +```py +class Solution: + def removeElement(self, nums: List[int], val: int) -> int: + i = 0 + for j in range(len(nums)): + if nums[j] != val: + nums[i] = nums[j] + i += 1 + return i +``` +