![]() ![]() Note that the five elements can be returned in any order.Are you studying for that next coding interview but don’t know where to start? Or are you looking for a concise, easy-to-understand study guide with everything you need to know? Or are you looking for a powerful advantage over the competition to guarantee you that awesome job you’ve always wanted at your dream company? It does not matter what you leave beyond the returned k (hence they are underscores).Įxample 2: Input: nums =, val = 2Įxplanation: Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4. If all assertions pass, then your solution will be accepted.Įxample 1: Input: nums =, val = 3Įxplanation: Your function should return k = 2, with the first two elements of nums being 2. Sort(nums, 0, k) // Sort the first k elements of nums Int k = removeElement(nums, val) // Calls your implementation It is sorted with no values equaling val. Int expectedNums = // The expected answer with correct length. The judge will test your solution with the following code: int nums = // Input array You must do this by modifying the input array in-place with O(1) extra memory. Return k after placing the final result in the first k slots of nums.ĭo not allocate extra space for another array. It does not matter what you leave beyond the first k elements. More formally, if there are k elements after removing the duplicates, then the first k elements of nums should hold the final result. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. The relative order of the elements may be changed. Given an integer array nums and an integer val, remove all occurrences of val in nums in-place.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |