本文整理汇总了Python中solution.Solution.twoSum方法的典型用法代码示例。如果您正苦于以下问题:Python Solution.twoSum方法的具体用法?Python Solution.twoSum怎么用?Python Solution.twoSum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solution.Solution
的用法示例。
在下文中一共展示了Solution.twoSum方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import twoSum [as 别名]
def main():
solution = Solution()
numbers = None
for line in stdin:
if numbers is None:
numbers = []
for string in line.split():
numbers.append(int(string))
else:
target = int(line)
indices = solution.twoSum(numbers, target)
print indices[0], indices[1]
numbers = None
示例2: Solution
# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import twoSum [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from solution import Solution
numbers = [2, 7, 11, 15]
target = 17
sol = Solution()
index = sol.twoSum(numbers, target)
print("index1=%d, index2=%d" % index)
示例3: test
# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import twoSum [as 别名]
def test():
sol = Solution()
assert sol.twoSum([2, 7, 11, 15], 9) == [1, 2]
assert sol.twoSum([15, 1, 11, 7, 2], 18) == [3, 4]