Last active
          May 24, 2023 17:41 
        
      - 
      
- 
        Save CristianLlanos/e95ca23140edd889eb2c58b8f3446e5c to your computer and use it in GitHub Desktop. 
    Remove Element
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /* | |
| * https://leetcode.com/problems/remove-element/description/?envType=study-plan-v2&id=top-interview-150 | |
| */ | |
| function removeElement(nums: number[], val: number): number { | |
| /* | |
| I1: nums = [l(k(3)), 2, 2, 3], val = 3 | |
| I2: nums = [l(2), k(2), 2, 3], val = 3 | |
| I3: nums = [2, l(2), k(2), 3], val = 3 | |
| I4: nums = [2, 2, l(3), k(3)], val = 3 | |
| */ | |
| let l = 0, k = 0; | |
| while (k < nums.length) { | |
| nums[l] = nums[k]; | |
| if (nums[l] !== val) { | |
| l++ | |
| } | |
| k++; | |
| } | |
| return l; | |
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function removeElement(nums: number[], val: number): number { | |
| /* | |
| I1: nums = [l(k(3)), 2, 2, 3], val = 3 | |
| I2: nums = [l(2), k(2), 2, 3], val = 3 | |
| I3: nums = [2, l(2), k(2), 3], val = 3 | |
| I4: nums = [2, 2, l(3), k(3)], val = 3 | |
| */ | |
| let l = 0; | |
| for (let k = 0; k < nums.length; k++) { | |
| nums[l] = nums[k]; | |
| if (nums[l] !== val) { | |
| l++ | |
| } | |
| } | |
| return l; | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment