Java: easy to understand solution: 0ms


  • 0
    D
    public class Solution {
        public int removeElement(int[] a, int val) {
            int len=a.length;
            for(int i=0;i<len;i++){
                 if((a[i]^val)==0){
                     int temp=a[len-1];
                      a[len-1]=a[i];
                      a[i]=temp;
                      len--;
                      i--;
                 }
                 
            }
            return len;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.