😀
OJ Practices
  • Introduction
  • Leetcode
    • Tree
      • 94 Binary Tree Inorder Traversal
      • 98 Validate Binary Search Tree
      • 99 Recover Binary Search Tree
      • 100 Same Tree
      • 101 Symmetric Tree
      • 102 Binary Tree Level Order Traversal
      • 103 Binary Tree Zigzag Level Order Traversal
      • 104 Maximum Depth of Binary Tree
      • 105 Construct Binary Tree from Preorder and Inorder Traversal
      • 106 Construct Binary Tree from Inorder and Postorder Traversal
      • 107 Binary Tree Level Order Traversal II
      • 108 Convert Sorted Array to Binary Search Tree
      • 110 Balanced Binary Tree
      • 111 Minimum Depth of Binary Tree
      • 112 Path Sum
      • 113 Path Sum II
      • 114 Flatten Binary Tree to Linked List
      • 116 Populating Next Right Pointers in Each Node
      • 117 Populating Next Right Pointers in Each Node II
      • 124 Binary Tree Maximum Path Sum
      • 129 Sum Root to Leaf Numbers
      • 144 Binary Tree Preorder Traversal
      • 145 Binary Tree Postorder Traversal
      • 156 Binary Tree Upside Down
      • 173 Binary Search Tree Iterator
      • 199 Binary Tree Right Side View
      • 222 Count Complete Tree Nodes
      • 226 Invert Binary Tree
      • 230 Kth Smallest Element in a BST
      • 235 Lowest Common Ancestor of a Binary Search Tree
      • 236 Lowest Common Ancestor of a Binary Tree
      • 250 Count Univalue Subtrees
      • 255 Verify Preorder Sequence in Binary Search Tree
      • 257 Binary Tree Paths
      • 270 Closest Binary Search Tree Value
      • 272 Closest Binary Search Tree Value II
      • 285 Inorder Successor in BST
      • 297 Serialize and Deserialize Binary Tree
      • 314 Binary Tree Vertical Order Traversal
      • 333 Largest BST Subtree
      • 366 Find Leaves of Binary Tree
      • 404 Sum of Left Leaves
      • 437 Path Sum III
      • 449 Serialize and Deserialize BST
      • 450 Delete Node in a BST
      • 501 Find Mode in Binary Search Tree
      • 508 Most Frequent Subtree Sum
      • 513 Find Bottom Left Tree Value
      • 515 Find Largest Value in Each Tree Row
      • 536 Construct Binary Tree from String
      • 538 Convert BST to Greater Tree
      • 543 Diameter of Binary Tree
      • 545 Boundary of Binary Tree
      • 549 Binary Tree Longest Consecutive Sequence II
      • 563 Binary Tree Tilt
      • 572 Subtree of Another Tree
      • 582 Kill Process
      • 606 Construct String from Binary Tree
      • 617 Merge Two Binary Trees
      • 623 Add One Row to Tree
      • 637 Average of Levels in Binary Tree
      • 652 Find Duplicate Subtrees
      • 653 Two Sum IV - Input is a BST
      • 654 Maximum Binary Tree
      • 655 Print Binary Tree
      • 662 Maximum Width of Binary Tree
      • 663 Equal Tree Partition
      • 666 Path Sum IV
      • 669 Trim a Binary Search Tree
      • 671 Second Minimum Node In a Binary Tree
      • 687 Longest Univalue Path
      • 742 Closest Leaf in a Binary Tree
      • 814 Binary Tree Pruning
      • 834 Sum of Distances in Tree
    • Dynamic Programming
      • LIS
        • 300 Longest Increasing Subsequence
        • 334 Increasing Triplet Subsequence
        • 354 Russian Doll Envelopes
        • 368 Largest Divisible Subset
        • 646 Maximum Length of Pair Chain
        • 673 Number of Longest Increasing Subsequence
      • LCS
        • 5 Longest Palindromic Substring
        • 72 Edit Distance
        • 115 Distinct Subsequences
        • 392 Is Subsequence
        • 516 Longest Palindromic Subsequence
        • 583 Delete Operation for Two Strings
        • 647 Palindromic Substrings
        • 712 Minimum ASCII Delete Sum for Two Strings
      • Knapsack Problem
        • 322 Coin Change
        • 377 Combination Sum IV
        • 416 Partition Equal Subset Sum
        • 474 Ones and Zeroes
        • 494 Target Sum
        • 518 Coin Change 2
      • Interval DP
        • 132 Palindrome Partitioning II
        • 312 Burst Balloons
        • 375 Guess Number Higher or Lower II
        • 471 Encode String with Shortest Length
        • 486 Predict the Winner
        • 516 Longest Palindromic Subsequence
        • 546 Remove Boxes
        • 664 Strange Printer
      • 10 Regular Expression Matching
      • 32 Longest Valid Parentheses
      • 44 Wildcard Matching
      • 53 Maximum Subarray
      • 62 Unique Paths
      • 63 Unique Paths II
      • 64 Minimum Path Sum
      • 70 Climbing Stairs
      • 85 Maximal Rectangle
      • 87 Scramble String
      • 91 Decode Ways
      • 95 Unique Binary Search Trees II
      • 96 Unique Binary Search Trees
      • 97 Interleaving String
      • 120 Triangle
      • 121 Best Time to Buy and Sell Stock
      • 122 Best Time to Buy and Sell Stock II
      • 123 Best Time to Buy and Sell Stock III
      • 139 Word Break
      • 140 Word Break II
      • 152 Maximum Product Subarray
      • 174 Dungeon Game
      • 188 Best Time to Buy and Sell Stock IV
      • 198 House Robber
      • 213 House Robber II
      • 221 Maximal Square
      • 238 Product of Array Except Self
      • 256 Paint House
      • 264 Ugly Number II
      • 265 Paint House II
      • 276 Paint Fence
      • 279 Perfect Squares
      • 303 Range Sum Query - Immutable
      • 304 Range Sum Query 2D - Immutable
      • 309 Best Time to Buy and Sell Stock with Cooldown
      • 321 Create Maximum Number
      • 338 Counting Bits
      • 343 Integer Break
      • 361 Bomb Enemy
      • 363 Max Sum of Rectangle No Larger Than K
      • 403 Frog Jump
      • 410 Split Array Largest Sum
      • 413 Arithmetic Slices
      • 418 Sentence Screen Fitting
      • 446 Arithmetic Slices II - Subsequence
      • 464 Can I Win
      • 467 Unique Substrings in Wraparound String
      • 514 Freedom Trail
      • 517 Super Washing Machines
      • 523 Continuous Subarray Sum
      • 552 Student Attendance Record II
      • 562 Longest Line of Consecutive One in Matrix
      • 568 Maximum Vacation Days
      • 576 Out of Boundary Paths
      • 600 Non-negative Integers without Consecutive Ones
      • 629 K Inverse Pairs Array
      • 638 Shopping Offers
      • 639 Decode Ways II
      • 650 2 Keys Keyboard
      • 651 4 Keys Keyboard
      • 656 Coin Path
      • 688 Knight Probability in Chessboard
      • 689 Maximum Sum of 3 Non-Overlapping Subarrays
      • 691 Stickers to Spell Word
      • 698 Partition to K Equal Sum Subsets
      • 714 Best Time to Buy and Sell Stock with Transaction Fee
      • 718 Maximum Length of Repeated Subarray
      • 727 Minimum Window Subsequence
      • 730 Count Different Palindromic Subsequences
      • 740 Delete and Earn
      • 741 Cherry Pickup
      • 746 Min Cost Climbing Stairs
      • 750 Number Of Corner Rectangles
      • 764 Largest Plus Sign
      • 787 Cheapest Flights Within K Stops
      • 790 Domino and Tromino Tiling
      • 801 Minimum Swaps To Make Sequences Increasing
      • 808 Soup Servings
      • 813 Largest Sum of Averages
    • Depth-First-Search
      • Memoization
        • 139 Word Break
        • 140 Word Break II
        • 276 Paint Fence
        • 294 Flip Game II
        • 329 Longest Increasing Path in a Matrix
        • 337 House Robber III
        • 375 Guess Number Higher or Lower II
        • 514 Freedom Trail
        • 568 Maximum Vacation Days
        • 638 Shopping Offers
        • 808 Soup Servings
    • Breadth-First Search
      • 126 Word Ladder II
      • 127 Word Ladder
      • 130 Surrounded Regions
      • 133 Clone Graph
      • 200 Number of Islands
      • 261 Graph Valid Tree
      • 279 Perfect Squares
      • 286 Walls and Gates
      • 301 Remove Invalid Parentheses
      • 310 Minimum Height Trees
      • 317 Shortest Distance from All Buildings
      • 323 Number of Connected Components in an Undirected Graph
      • 365 Water and Jug Problem
      • 397 Integer Replacement
      • 407 Trapping Rain Water II
      • 417 Pacific Atlantic Water Flow
      • 429 N-ary Tree Level Order Traversal
      • 433 Minimum Genetic Mutation
      • 490 The Maze
      • 499 The Maze III
      • 505 The Maze II
      • 529 Minesweeper
      • 542 01 Matrix
      • 675 Cut Off Trees for Golf Event
      • 690 Employee Importance
      • 743 Network Delay Time
      • 752 Open the Lock
      • 773 Sliding Puzzle
      • 785 Is Graph Bipartite?
      • 787 Cheapest Flights Within K Stops
      • 815 Bus Routes
      • 818 Race Car
      • 847 Shortest Path Visiting All Nodes
      • 854 K-Similar Strings
      • 864 Shortest Path to Get All Keys
      • 886 Possible Bipartition
      • 909 Snakes and Ladders
      • 913 Cat and Mouse
      • 934 Shortest Bridge
    • Two Pointers
      • 3 Longest Substring Without Repeating Characters
      • 11 Container With Most Water
      • 15 3Sum
      • 16 3Sum Closest
      • 18 4Sum
      • 26 Remove Duplicates from Sorted Array
      • 27 Remove Element
      • 30 Substring with Concatenation of All Words
      • 42 Trapping Rain Water
      • 76 Minimum Window Substring
      • 80 Remove Duplicates from Sorted Array II
      • 88 Merge Sorted Array
      • 125 Valid Palindrome
      • 159 Longest Substring with At Most Two Distinct Characters
      • 167 Two Sum II - Input array is sorted
      • 202 Happy Number
      • 209 Minimum Size Subarray Sum
      • 259 3Sum Smaller
      • 283 Move Zeroes
      • 287 Find the Duplicate Number
      • 340 Longest Substring with At Most K Distinct Characters
      • 344 Reverse String
      • 345 Reverse Vowels of a String
      • 349 Intersection of Two Arrays
      • 350 Intersection of Two Arrays II
      • 360 Sort Transformed Array
      • 395 Longest Substring with At Least K Repeating Characters
      • 424 Longest Repeating Character Replacement
      • 438 Find All Anagrams in a String
      • 487 Max Consecutive Ones II
      • 524 Longest Word in Dictionary through Deleting
      • 532 K-diff Pairs in an Array
      • 567 Permutation in String
      • 611 Valid Triangle Number
      • 632 Smallest Range
      • 713 Subarray Product Less Than K
      • 723 Candy Crush
      • 763 Partition Labels
      • 826 Most Profit Assigning Work
      • 828 Unique Letter String
      • 838 Push Dominoes
      • 844 Backspace String Compare
      • 845 Longest Mountain in Array
      • 881 Boats to Save People
      • 904 Fruit Into Baskets
      • 457 Circular Array Loop
    • Linked List
      • 2 Add Two Numbers
      • 19 Remove Nth Node From End of List
      • 21 Merge Two Sorted Lists
      • 23 Merge k Sorted Lists
      • 24 Swap Nodes in Pairs
      • 25 Reverse Nodes in k-Group
      • 61 Rotate List
      • 82 Remove Duplicates from Sorted List II
      • 83 Remove Duplicates from Sorted List
      • 86 Partition List
      • 92 Reverse Linked List II
      • 109 Convert Sorted List to Binary Search Tree
      • 138 Copy List with Random Pointer
      • 141 Linked List Cycle
      • 142 Linked List Cycle II
      • 143 Reorder List
      • 147 Insertion Sort List
      • 148 Sort List
      • 160 Intersection of Two Linked Lists
      • 203 Remove Linked List Elements
      • 206 Reverse Linked List
      • 234 Palindrome Linked List
      • 237 Delete Node in a Linked List
      • 328 Odd Even Linked List
      • 369 Plus One Linked List
      • 379 Design Phone Directory
      • 426 Convert Binary Search Tree to Sorted Doubly Linked List
      • 430 Flatten a Multilevel Doubly Linked List
      • 445 Add Two Numbers II
      • 707 Design Linked List
      • 708 Insert into a Cyclic Sorted List
      • 725 Split Linked List in Parts
      • 817 Linked List Components
      • 876 Middle of the Linked List
    • Backtracking
      • 17 Letter Combinations of a Phone Number
      • 22 Generate Parentheses
      • 37 Sudoku Solver
      • 39 Combination Sum
      • 40 Combination Sum II
      • 46 Permutations
      • 47 Permutations II
      • 51 N-Queens
      • 52 N-Queens II
      • 60 Permutation Sequence
      • 77 Combinations
      • 78 Subsets
      • 79 Word Search
      • 89 Gray Code
      • 90 Subsets II
      • 93 Restore IP Addresses
      • 131 Palindrome Partitioning
      • 212 Word Search II
      • 216 Combination Sum III
      • 254 Factor Combinations
      • 267 Palindrome Permutation II
      • 282 Expression Add Operators
      • 291 Word Pattern II
      • 301 Remove Invalid Parentheses
      • 306 Additive Number
      • 320 Generalized Abbreviation
      • 357 Count Numbers with Unique Digits
      • 401 Binary Watch
      • 411 Minimum Unique Word Abbreviation
      • 425 Word Squares
      • 473 Matchsticks to Square
      • 491 Increasing Subsequences
      • 526 Beautiful Arrangement
      • 679 24 Game
      • 698 Partition to K Equal Sum Subsets
      • 784 Letter Case Permutation
      • 797 All Paths From Source to Target
      • 842 Split Array into Fibonacci Sequence
    • Binary Search
      • 4 Median of Two Sorted Arrays
      • 29 Divide Two Integers
      • 33 Search in Rotated Sorted Array
      • 34 Search for a Range
      • 35 Search Insert Position
      • 50 Pow(x, n)
      • 69 Sqrt(x)
      • 74 Search a 2D Matrix
      • 81 Search in Rotated Sorted Array II
      • 153 Find Minimum in Rotated Sorted Array
      • 154 Find Minimum in Rotated Sorted Array II
      • 162 Find Peak Element
      • 209 Minimum Size Subarray Sum
      • 240 Search a 2D Matrix II
      • 275 H-Index II
      • 278 First Bad Version
      • 287 Find the Duplicate Number
      • 300 Longest Increasing Subsequence
      • 302 Smallest Rectangle Enclosing Black Pixels
      • 349 Intersection of Two Arrays
      • 350 Intersection of Two Arrays II
      • 354 Russian Doll Envelopes
      • 367 Valid Perfect Square
      • 374 Guess Number Higher or Lower
      • 378 Kth Smallest Element in a Sorted Matrix
      • 410 Split Array Largest Sum
      • 436 Find Right Interval
      • 441 Arranging Coins
      • 475 Heaters
      • 483 Smallest Good Base
      • 497 Random Point in Non-overlapping Rectangles
      • 528 Random Pick with Weight
      • 540 Single Element in a Sorted Array
      • 644 Maximum Average Subarray II
      • 658 Find K Closest Elements
      • 668 Kth Smallest Number in Multiplication Table
      • 702 Search in a Sorted Array of Unknown Size
      • 704 Binary Search
      • 710 Random Pick with Blacklist
      • 718 Maximum Length of Repeated Subarray
      • 719 Find K-th Smallest Pair Distance
      • 744 Find Smallest Letter Greater Than Target
      • 774 Minimize Max Distance to Gas Station
      • 778 Swim in Rising Water
      • 786 K-th Smallest Prime Fraction
      • 793 Preimage Size of Factorial Zeroes Function
      • 852 Peak Index in a Mountain Array
      • 862 Shortest Subarray with Sum at Least K
      • 875 Koko Eating Bananas
      • 878 Nth Magical Number
      • 887 Super Egg Drop
      • 911 Online Election
    • Union Find
      • 128 Longest Consecutive Sequence
      • 130 Surrounded Regions
      • 200 Number of Islands
      • 261 Graph Valid Tree
      • 305 Number of Islands II
      • 323 Number of Connected Components in an Undirected Graph
      • 399 Evaluate Division
      • 547 Friend Circles
      • 684 Redundant Connection
      • 685 Redundant Connection II
      • 695 Max Area of Island
      • 721 Accounts Merge
      • 737 Sentence Similarity II
      • 765 Couples Holding Hands
      • 778 Swim in Rising Water
      • 803 Bricks Falling When Hit
      • 839 Similar String Groups
      • 924 Minimize Malware Spread
      • 928 Minimize Malware Spread II
      • 947 Most Stones Removed with Same Row or Column
      • 952 Largest Component Size by Common Factor
      • 959 Regions Cut By Slashes
    • Trie
      • 208 Implement Trie (Prefix Tree)
      • 211 Add and Search Word - Data structure design
      • 212 Word Search II
      • 336 Palindrome Pairs
      • 421 Maximum XOR of Two Numbers in an Array
      • 425 Word Squares
      • 472 Concatenated Words
      • 527 Word Abbreviation
      • 588 Design In-Memory File System
      • 642 Design Search Autocomplete System
      • 648 Replace Words
      • 676 Implement Magic Dictionary
      • 677 Map Sum Pairs
      • 692 Top K Frequent Words
      • 720 Longest Word in Dictionary
      • 745 Prefix and Suffix Search
    • Sort
      • 49 Group Anagrams
      • 75 Sort Colors
      • 164 Maximum Gap
      • 179 Largest Number
      • 274 H-Index
      • 280 Wiggle Sort
      • 296 Best Meeting Point
      • 315 Count of Smaller Numbers After Self
      • 324 Wiggle Sort II
      • 327 Count of Range Sum
      • 406 Queue Reconstruction by Height
      • 462 Minimum Moves to Equal Array Elements II
      • 493 Reverse Pairs
      • 846 Hand of Straights
    • Heap
      • 215 Kth Largest Element in an Array
      • 218 The Skyline Problem
      • 239 Sliding Window Maximum
      • 253 Meeting Rooms II
      • 264 Ugly Number II
      • 295 Find Median from Data Stream
      • 313 Super Ugly Number
      • 347 Top K Frequent Elements
      • 355 Design Twitter
      • 358 Rearrange String k Distance Apart
      • 373 Find K Pairs with Smallest Sums
      • 378 Kth Smallest Element in a Sorted Matrix
      • 407 Trapping Rain Water II
      • 451 Sort Characters By Frequency
      • 480 Sliding Window Median
      • 502 IPO
      • 632 Smallest Range
      • 659 Split Array into Consecutive Subsequences
      • 668 Kth Smallest Number in Multiplication Table
      • 692 Top K Frequent Words
      • 703 Kth Largest Element in a Stream
      • 719 Find K-th Smallest Pair Distance
      • 743 Network Delay Time
      • 759 Employee Free Time
      • 767 Reorganize String
      • 778 Swim in Rising Water
      • 786 K-th Smallest Prime Fraction
      • 787 Cheapest Flights Within K Stops
      • 818 Race Car
      • 855 Exam Room
      • 857 Minimum Cost to Hire K Workers
      • 864 Shortest Path to Get All Keys
      • 871 Minimum Number of Refueling Stops
      • 882 Reachable Nodes In Subdivided Graph
    • Randomness
      • 384 Shuffle an Array
      • 470 Implement Rand10() Using Rand7()
      • 478 Generate Random Point in a Circle
      • 497 Random Point in Non-overlapping Rectangles
      • 519 Random Flip Matrix
      • 528 Random Pick with Weight
      • 710 Random Pick with Blacklist
    • Topological Sort
      • 207 Course Schedule
      • 210 Course Schedule II
      • 269 Alien Dictionary
      • 444 Sequence Reconstruction
      • 802 Find Eventual Safe States
    • Stack
      • 20 Valid Parentheses
      • 42 Trapping Rain Water
      • 71 Simplify Path
      • 84 Largest Rectangle in Histogram
      • 85 Maximal Rectangle
      • 150 Evaluate Reverse Polish Notation
      • 155 Min Stack
      • 224 Basic Calculator
      • 227 Basic Calculator II
      • 225 Implement Stack using Queues
      • 232 Implement Queue using Stacks
      • 316 Remove Duplicate Letters
      • 331 Verify Preorder Serialization of a Binary Tree
      • 341 Flatten Nested List Iterator
      • 385 Mini Parser
      • 394 Decode String
      • 402 Remove K Digits
      • 439 Ternary Expression Parser
      • 456 132 Pattern
      • 484 Find Permutation
      • 496 Next Greater Element I
      • 503 Next Greater Element II
      • 591 Tag Validator
      • 636 Exclusive Time of Functions
      • 682 Baseball Game
      • 726 Number of Atoms
      • 735 Asteroid Collision
      • 739 Daily Temperatures
      • 768 Max Chunks To Make Sorted II
      • 770 Basic Calculator IV
      • 772 Basic Calculator III
      • 844 Backspace String Compare
      • 853 Car Fleet
      • 856 Score of Parentheses
      • 880 Decoded String at Index
      • 895 Maximum Frequency Stack
      • 901 Online Stock Span
      • 907 Sum of Subarray Minimums
      • 946 Validate Stack Sequences
      • 962 Maximum Width Ramp
      • 975 Odd Even Jump
    • Hash Table
      • 1 Two Sum
      • 3 Longest Substring Without Repeating Characters
      • 18 4Sum
      • 30 Substring with Concatenation of All Words
      • 37 Sudoku Solver
      • 49 Group Anagrams
      • 76 Minimum Window Substring
      • 136 Single Number
      • 138 Copy List with Random Pointer
      • 149 Max Points on a Line
      • 159 Longest Substring with At Most Two Distinct Characters
      • 166 Fraction to Recurring Decimal
      • 170 Two Sum III - Data structure design
      • 187 Repeated DNA Sequences
      • 202 Happy Number
      • 204 Count Primes
      • 205 Isomorphic Strings
      • 217 Contains Duplicate
      • 219 Contains Duplicate II
      • 242 Valid Anagram
      • 244 Shortest Word Distance II
      • 246 Strobogrammatic Number
      • 249 Group Shifted Strings
      • 266 Palindrome Permutation
      • 274 H-Index
      • 288 Unique Word Abbreviation
      • 290 Word Pattern
      • 299 Bulls and Cows
      • 311 Sparse Matrix Multiplication
      • 314 Binary Tree Vertical Order Traversal
      • 325 Maximum Size Subarray Sum Equals k
      • 336 Palindrome Pairs
      • 340 Longest Substring with At Most K Distinct Characters
      • 347 Top K Frequent Elements
      • 349 Intersection of Two Arrays
      • 350 Intersection of Two Arrays II
      • 355 Design Twitter
      • 356 Line Reflection
      • 358 Rearrange String k Distance Apart
      • 359 Logger Rate Limiter
      • 380 Insert Delete GetRandom O(1)
      • 381 Insert Delete GetRandom O(1) - Duplicates allowed
      • 387 First Unique Character in a String
      • 389 Find the Difference
      • 409 Longest Palindrome
      • 438 Find All Anagrams in a String
      • 447 Number of Boomerangs
      • 451 Sort Characters By Frequency
      • 454 4Sum II
      • 463 Island Perimeter
      • 500 Keyboard Row
      • 508 Most Frequent Subtree Sum
      • 525 Contiguous Array
      • 554 Brick Wall
      • 560 Subarray Sum Equals K
      • 575 Distribute Candies
      • 594 Longest Harmonious Subsequence
      • 599 Minimum Index Sum of Two Lists
      • 609 Find Duplicate File in System
      • 624 Maximum Distance in Arrays
      • 632 Smallest Range
      • 645 Set Mismatch
      • 648 Replace Words
      • 676 Implement Magic Dictionary
      • 692 Top K Frequent Words
      • 694 Number of Distinct Islands
      • 705 Design HashSet
      • 706 Design HashMap
Powered by GitBook
On this page
  • 27. Remove Element
  • 1. Question
  • 2. Implementation
  • 3. Time & Space Complexity

Was this helpful?

  1. Leetcode
  2. Two Pointers

27 Remove Element

Previous26 Remove Duplicates from Sorted ArrayNext30 Substring with Concatenation of All Words

Last updated 5 years ago

Was this helpful?

27.

1. Question

Given an array and a value, remove all instances of that value and return the new length.

Do not allocate extra space for another array, you must do this by modifying the input array with O(1) extra memory.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

Example:

Given nums = [3,2,2,3], val = 3,

Your function should return length = 2, with the first two elements of nums being 2.

2. Implementation

public class Solution {
    public int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

        int index = 0;
        for (int num : nums) {
            if (num != val) {
                nums[index++] = num;
            }
        }
        return index;
    }
}

3. Time & Space Complexity

时间复杂度O(n), 空间复杂度O(1)

Remove Element
in-place
in-place