主函数定义

leetcode中主函数的定义问题

如twosum问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution(object):
def twoSum(self, nums, target):
if len(nums) <= 1:
return False
buff_dict = {}
for i in range(len(nums)):
if nums[i] in buff_dict:
return [buff_dict[nums[i]], i]
else:
buff_dict[target - nums[i]] = i
<!--more-->
"""
def main():
nums = [2, 7, 11, 15]
target = 9
s = Solution()
print(s.twoSum(nums, target))
"""
if __name__ == "__main__":
nums = [2, 7, 11, 15]
target = 9
s = Solution()
print(s.twoSum(nums, target))