public static void main(String[] args) throws UnsupportedEncodingException {
int[] ints = { 1, 5, 10, 11 , 13, 18, 22 ,55 };
int find = 23;
int start = 0;
int end = ints.length - 1;
while (ints[start] >= find) {
System.out.println("都比他大哦!");
return;
}
while (end > start) {
if (ints[start] + ints[end] == find) {
System.out.println(ints[start] + " + " + ints[end] + " = "
+ find);
end--;
start++;
} else if (ints[start] + ints[end] < find) {
start++;
} else if (ints[start] + ints[end] > find) {
end--;
}
System.out.println(start +" "+end);
}
}
一个排好序的数组,找出两数之和为m的所有组合
最新推荐文章于 2022-04-08 17:51:13 发布