Комментарии:
Nalla question da👍👍👍
ОтветитьNice question 🔥🔥
Ответить// Time complexity: O(N) + Space complexity: O(1)
int equilibriumPoint(long numbers[], int n) {
if (numbers == null || n == 0) return -1;
if (n == 1) return 1;
long totalSum = 0;
for (int i = 0; i < numbers.length; i++) totalSum += numbers[i];
long leftSum = numbers[0];
for (int i = 1; i < numbers.length; i++) {
long rightSum = totalSum - leftSum - numbers[i];
if (leftSum == rightSum) return i + 1;
leftSum += numbers[i];
}
return -1;
}
BRo eqpoint is never used here
ОтветитьEnna language bro use pannirikinga
ОтветитьNice explanation bro
ОтветитьAnna indha array la last value 0 va irundhuchuna
Ответитьpublic class equillibrium {
public static int Arrayequillibrium(int arr[],int n)
{
int left=0;
int right=n-1;
int mid=n/2;
int ans1=0;
int ans2=0;
while(left<mid&&right>mid)
{
ans1+=arr[left];
left++;
ans2+=arr[right];
right--;
}
if(ans1==ans2)
return mid;
else
return -1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr={ -7, 1, 5, 2, -4, 3, 0 };
int n=arr.length;
System.out.print(Arrayequillibrium(arr,n));
}
}
bro naa 2 years late for commenting my code😂
Worst explain
Ответитьbro how to think like this?
Ответить