Skip to content

Latest commit

 

History

History
31 lines (27 loc) · 399 Bytes

27.移除元素.md

File metadata and controls

31 lines (27 loc) · 399 Bytes
title categories
移除元素
leetcode
leetcode题解
package main

/*
 * @lc app=leetcode.cn id=27 lang=golang
 *
 * [27] 移除元素
 */

// @lc code=start
func removeElement(nums []int, val int) int {
	slow, fast := 0, 0
	for fast < len(nums) {
		if val != nums[fast] {
			nums[slow] = nums[fast]
			slow++
		}
		fast++

	}
	return len(nums[:slow])
}

// @lc code=end