Created
March 1, 2015 16:29
-
-
Save vporoshok/0e44a1515080c0cc33ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
def has_sum(x, S): | |
i = 0 | |
j = len(S) - 1 | |
while i < j: | |
if S[i] + S[j] < x: | |
i += 1 | |
elif S[i] + S[j] > x: | |
j -= 1 | |
else: | |
return True | |
return False | |
if __name__ == '__main__': | |
x = 56 | |
S = [1, 3, 4, 12, 22, 34, 98] # На сортировку как раз потратили O(n*lg(n)) | |
print('Yes' if has_sum(x, S) else 'No') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment