- public static void main(String[] args) throws UnsupportedEncodingException {
- int[] ints = { 1, 3, 10, 12 , 13, 18, 22 ,58 };
- 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的所有组合
最新推荐文章于 2020-11-01 19:11:09 发布