1、最长递增数列
public class Test5 {
public static void main(String[] args){
int []n = {1,7,7,8,3,6,7,2};
System.out.println(getRes(n));
}
public static int getRes(int []nums){
int len = nums.length;
if (len < 2) return len;
int count = 1;
int res = 1;
for (int i = 0; i < len - 1; i++) {
boolean flag = false;
while (i < len - 1 && nums[i + 1] > nums[i]) {
count++;
i++;
flag = true;
}
res = Math.max(count, res);
count = 1;
if (flag) i--;
}
return res;
}
}
2、最少众倍数
public static int getRes2(int a, int b, int c, int d, int e){
int []nums = {a, b, c, d, e};
Arrays.sort(nums);
int count = 0;
for (int i = 2; i < 5; i++) {
for (int j = 0; j <= i; j++) {
if (nums[i] % nums[j] == 0) {
count++;
}
if (count >= 3) {
return nums[i];
}
}
count = 0;
}
return -1;
}
3、整数点在圆上
public static int getRes3(int rSquare){
int N = 0;
long r = 0;
double r_double = Math.sqrt(rSquare);
long r_long = (long) r_double;
double y_double = 0.0;
long y_long = 0;
if (r_double == r_long) {
r = r_long - 1;
N = N + 1;
} else {
r = r_long;
}
for (long x = 1; x <= r; x++) {
y_double = Math.sqrt(rSquare - x * x);
y_long = (long) y_double;
if (y_long == y_double) {
if (x * x + y_long * y_long == rSquare) {
N = N + 1;
}
}
}
return N * 4;
//System.out.println(4 * N);
}