1 Star 0 Fork 216

周公卿 / python-learn

forked from mktime / python-learn 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
data-structure.py 617 Bytes
一键复制 编辑 原始数据 按行查看 历史
mr.github 提交于 2014-07-09 12:34 . learn datas tructure
''' find a pair of numbers that the sum is equal for asked in an sorted array
'''
def find_two_sum(data, sum):
begin_pos = 0
end_pos = len(data) - 1
while begin_pos < end_pos:
if (data[begin_pos] + data[end_pos]) > sum:
end_pos -= 1
elif (data[begin_pos] + data[end_pos]) < sum:
begin_pos += 1
else:
print "FIND:[%d,%d]" % (data[begin_pos], data[end_pos])
end_pos -= 1
begin_pos += 1
def test_find_two():
data = [0, 1, 2, 3, 5, 7, 9, 13, 14]
find_two_sum(data, 8)
if __name__ == '__main__':
test_find_two()
Python
1
https://gitee.com/zhou-gongqing/python-learn.git
git@gitee.com:zhou-gongqing/python-learn.git
zhou-gongqing
python-learn
python-learn
master

搜索帮助