Find the equilibrium index in the array.


  • 0
    M
    ArrayList<Integer> equilibrium (int [] arr)
    {
        ArrayList<Integer> result_array = new ArrayList<Integer>();	
        int result=0;
        int sum=0;
        int n=arr.length;
    
    	int leftSum=0;
    
        for(int i=0; i<n; i++)
            sum + = arr[i];
    
       for(i=0 ; i<n ;i++)
       {
    	sum = sum - arr[i];
    	if(leftSum==sum)
    		result_arr.add(i);
             leftSum+=arr[i];
        } 
        return result_array;
    }

Log in to reply
 

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