Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一个有关二分法的面试题 | 石锅拌饭 #1

Open
chunchengwei opened this issue Dec 4, 2018 · 0 comments
Open

一个有关二分法的面试题 | 石锅拌饭 #1

chunchengwei opened this issue Dec 4, 2018 · 0 comments

Comments

@chunchengwei
Copy link
Owner

https://chunchengwei.github.io/shua-ti/yi-ge-you-guan-er-fen-fa-de-mian-shi-ti/

问题:给定一个有序数组,再给定一个数c,判断数组中是否存在两个数a,b,满足a + b = c。要求时间复杂度$O(n)$,空间复杂度$O(1)$。
解决方法:利用首尾两个指针,计算首尾的和,如果小于c,就移动首指针+1,否则就移动尾指针-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant