python——LeetCode刷题
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                python——LeetCode刷题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                文章目錄(每天兩題)
 leetcode1 兩數之和
推薦使用下面的方法
#原文鏈接:https://blog.csdn.net/hua111hua/article/details/102915120 class Solution:def twoSum(self, nums, target):dict = {}for i in range(len(nums)):if target-nums[i] in dict:return [dict[target-nums[i]], i]else:dict[nums[i]] = ia = Solution() print(a.twoSum([1,2,4,5],3))書上的方法
def twoSum(nums, target):for i in range(len(nums) - 1):if target - nums[i] in nums[i+1:]:j = nums[i+1:].index(target - nums[i])return [i, i + j + 1]rList = twoSum([2, 7, 11, 15], 9)總結
以上是生活随笔為你收集整理的python——LeetCode刷题的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: pytorch学习知识点总结
 - 下一篇: python 中的路径. ./ .. .