Simple golang solution


  • 0
    Z
    func pivotIndex(nums []int) int {
        total := 0;
        for _,v := range nums{
            total += v;
        }
        tally := 0;
        for i,v:=range nums{
            if tally == (total-v-tally){
                return i;
            } 
            tally += v;
        }
        return -1;
    }
    

Log in to reply
 

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