sorted-array-pair-sum-closest-x:给定一个已排序的数组和一个数字x,在数组中找到总和最接近x的对

时间:2021-04-29 08:43:14
【文件属性】:
文件名称:sorted-array-pair-sum-closest-x:给定一个已排序的数组和一个数字x,在数组中找到总和最接近x的对
文件大小:6KB
文件格式:ZIP
更新时间:2021-04-29 08:43:14
Java 排序数组对总和最近 给定一个已排序的数组和一个数字x,在数组中找到总和最接近x的对 private static void printClosest(int[] arr, int n, int x) { int left = -1, right = -1; int diff = Integer.MAX_VALUE; for(int i=0, j=n-1; j>i; ) { if(Math.abs(arr[i] + arr[j] - x) < diff xss=removed xss=removed xss=removed> x) j--; else i++; } System.out.println(ar
【文件预览】:
sorted-array-pair-sum-closest-x-master
----.gitignore(278B)
----src()
--------algo()
----.classpath(295B)
----.settings()
--------org.eclipse.jdt.core.prefs(587B)
----README.md(2KB)
----.project(390B)

网友评论