leetcode打不开-Leetcode-problems-python:使用Python解决几个Leetcode算法问题

时间:2021-06-30 01:57:54
【文件属性】:
文件名称:leetcode打不开-Leetcode-problems-python:使用Python解决几个Leetcode算法问题
文件大小:7KB
文件格式:ZIP
更新时间:2021-06-30 01:57:54
系统开源 leetcode打不开Leetcode-算法-Python 使用Python解决几个Leetcode算法问题 简单的问题 1. 二和 给定一个整数数组,返回两个数字的索引,使它们相加为特定目标。 您可以假设每个输入都只有一个解决方案,并且您不能两次使用相同的元素。 Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. 代码: def twoSum ( nums ): for i in range ( len ( nums )): lkup = target - nums [ i ] if lkup in nums : k = nums . index ( lkup ) if i != k : return [ i , k ] else : continue 2. 最大子阵列 给定一个整数数组 nums,找出其总和最大的连续子数组(至少包含一个数字)并返回其总和。 Example: Input: [-2,1,-3,4,-1,2,1,-5
【文件预览】:
Leetcode-problems-python-master
----README.md(14KB)
----1-two-sum.py(559B)
----53-maximum-subarray.py(449B)

网友评论