创建类的对象以测试python方法
从Leetcode中的一个问题来看,这个解决方案是正确的,但希望通过创建一个实例,然后打印方法twoSum的结果,自己在VSCode中对其进行测试。但我不知道该怎么做创建类的对象以测试python方法,python,object,Python,Object,从Leetcode中的一个问题来看,这个解决方案是正确的,但希望通过创建一个实例,然后打印方法twoSum的结果,自己在VSCode中对其进行测试。但我不知道该怎么做 class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[in
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
count1 = 0
for i in nums:
count2 = 0
for j in nums:
if (i+j) == target and i != j:
return count1, count2
count2 +=1
count1 +=1
if __name__ == "__main__":
print(twoSum([2,7,11,15],9 ))
感谢您的帮助您首先必须通过执行以下操作来实例化
解决方案
实例-
s=Solution()
然后调用该方法-
s.twoSum([2, 7, 11, 15], 9)