-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFind_the_Pivot_Integer.java
More file actions
39 lines (38 loc) · 916 Bytes
/
Find_the_Pivot_Integer.java
File metadata and controls
39 lines (38 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.*;
import java.io.*;
import java.lang.*;
public class Find_the_Pivot_Integer {
class Solution {
public int pivotInteger(int n) {
int i= n*(n+1)/2;
int j = (int)Math.sqrt(i);
if(j*j==i) return j;
else return -1;
}
}
// class Solution {
// public int pivotInteger(int n) {
// for(int j = 1 ; j<=n ; j++)
// {
// int sum1 = 0;
// int sum2 = 0;
// for(int i = 1 ; i<=n ; i++)
// {
// if(i<=j)
// {
// sum1 = sum1 + i;
// }
// if(i>=j)
// {
// sum2 = sum2 + i;
// }
// }
// if(sum1==sum2)
// {
// return j;
// }
// }
// return -1;
// }
// }
}