How To Solve Leet Code 27. Remove Element And Exercise Tuple Unpacking And Value Swapping
27. Remove Element — LeetCode
1 min readMay 10, 2022
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,_,_]