int i = 0, j = array.length - 1; int min = Integer.MAX_VALUE; int left = i, right = j, result = 0, mutex = 0; while (i < j){ result = array[i] + array[j]; mutex = Math.abs(result); if (mutex < min){ min = mutex; left = i; right = j; } if (result > 0){ j--; } else if (result < 0){ i++; }else { min = 0; return; } }
点赞

相关推荐

牛客网
牛客企业服务