0

In flow i written code, now i don't understand why it working

Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Return k after placing the final result in the first k slots of nums. https://code.sololearn.com/caYlYmfZOIlm/?ref=app

15th Nov 2022, 12:34 AM
Prashant Priyadarshi
Prashant Priyadarshi - avatar
1 Réponse
+ 1
Prashant Priyadarshi the code is hard to read, isn't it? I took the liberty to rearrange it for my own understanding. Maybe you would benefit from seeing the revision: int i=0; for (int j = 1; j<nums.Length; j++) if (nums[j]!=nums[i]) nums[++i] = nums[j]; return i+1;
19th Nov 2022, 11:43 PM
Brian
Brian - avatar