How To Solve Leet Code 27. Remove Element And Exercise Tuple Unpacking And Value Swapping

The aim of this page📝is to make notes around 27. Remove Element — LeetCode Puzzle. My solution is extremely wordy, as I wanted to list all 4 combinations.

This puzzle is a nice example of tuple unpacking and the accompanying value swapping within a Python list.

1. ASSIGNMENT

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.
It does not matter what you leave beyond the first k elements.
Input: nums = [3,2,2,3], val = 3
Output: 2, nums = [2,2,_,_]

2. SOLUTION

3. RUBBERDUCK

4. LINKS

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store