auto commit

This commit is contained in:
CyC2018 2019-06-04 23:31:42 +08:00
parent 62f8d7cd4a
commit 8f2b92d915
3 changed files with 5 additions and 8 deletions

View File

@ -1,7 +1,6 @@
<div align="center">
<a href="https://github.com/CyC2018/CS-Notes/blob/master/other/download.md">离线阅读版本下载</a>
<a href="https://github.com/CyC2018/CS-Notes/blob/master/other/download.md">离线阅读版本下载Download for offline reading</a>
</div>
<br>
| &nbsp;算法&nbsp; | 操作系统 | &nbsp;网络&nbsp; | 面向对象 | &nbsp;&nbsp;数据库&nbsp;&nbsp; | &nbsp;&nbsp;&nbsp;Java&nbsp;&nbsp;&nbsp; | 系统设计 | &nbsp;&nbsp;&nbsp;工具&nbsp;&nbsp;&nbsp; | 编码实践 | &nbsp;&nbsp;&nbsp;后记&nbsp;&nbsp;&nbsp; |

View File

@ -147,6 +147,8 @@ public class BinarySearch {
更有效的方法是先将数组排序,然后使用双指针进行查找,时间复杂度为 O(N<sup>2</sup>)。
同样不适用与数组存在重复元素的情况。
```java
public class ThreeSumTwoPointer implements ThreeSum {
@ -157,13 +159,10 @@ public class ThreeSumTwoPointer implements ThreeSum {
Arrays.sort(nums);
for (int i = 0; i < N - 2; i++) {
int l = i + 1, h = N - 1, target = -nums[i];
if (i > 0 && nums[i] == nums[i - 1]) continue;
while (l < h) {
int sum = nums[l] + nums[h];
if (sum == target) {
cnt++;
while (l < h && nums[l] == nums[l + 1]) l++;
while (l < h && nums[h] == nums[h - 1]) h--;
l++;
h--;
} else if (sum < target) {

View File

@ -147,6 +147,8 @@ public class BinarySearch {
更有效的方法是先将数组排序,然后使用双指针进行查找,时间复杂度为 O(N<sup>2</sup>)。
同样不适用与数组存在重复元素的情况。
```java
public class ThreeSumTwoPointer implements ThreeSum {
@ -157,13 +159,10 @@ public class ThreeSumTwoPointer implements ThreeSum {
Arrays.sort(nums);
for (int i = 0; i < N - 2; i++) {
int l = i + 1, h = N - 1, target = -nums[i];
if (i > 0 && nums[i] == nums[i - 1]) continue;
while (l < h) {
int sum = nums[l] + nums[h];
if (sum == target) {
cnt++;
while (l < h && nums[l] == nums[l + 1]) l++;
while (l < h && nums[h] == nums[h - 1]) h--;
l++;
h--;
} else if (sum < target) {