LintCode:子数组之和
来源:互联网 发布:写编程到底什么意思 编辑:程序博客网 时间:2024/05/06 07:49
LintCode:子数组之和
方法一:O(n^2)复杂度:
Python
class Solution: """ @param nums: A list of integers @return: A list of integers includes the index of the first number and the index of the last number """ def subarraySum(self, nums): # write your code here ans = [] if len(nums) == 0: return ans m = len(nums) for i in range(m): sum = 0 for j in range(i, m): sum += nums[j] if sum == 0: return [i, j]
方法二:O(n)复杂度:
Python
class Solution: """ @param nums: A list of integers @return: A list of integers includes the index of the first number and the index of the last number """ def subarraySum(self, nums): # write your code here m = len(nums) d = {0:-1} tmp = 0 for i in range(m): tmp += nums[i] if tmp in d: return [d.get(tmp) + 1, i] d[tmp] = i
0 0
- LintCode:子数组之和
- lintcode ----子数组之和
- lintcode--子数组之和
- 子数组之和-LintCode
- LIntcode 子数组之和
- lintcode:子数组之和
- lintcode-子数组之和-138
- LintCode 138. 子数组之和
- [Lintcode] #138 子数组之和
- LintCode Subarray Sum 子数组之和
- 子数组之和为零 lintcode
- LintCode 138-子数组之和 JAVA
- [LintCode 138] 子数组之和(Python)
- [LintCode 41] 最大子数组之和(Python)
- lintcode 之子数组之和
- 子数组之和
- 最大子数组之和
- 最大子数组之和
- js页面上实现搜索
- 欢迎使用CSDN-markdown编辑器
- appium for python client scroll to view(not in current screen)
- Partition-方案二:通过 Insert with a subquery 方法
- 基于内容的图像检索引擎(以图搜图)
- LintCode:子数组之和
- uva624(DP)
- uva208
- Android Json解析工具类
- linux基础之文件查找
- 设计模式中的七个原则
- Android控件HorizontalScrollView/listview去掉滚动条
- sdutoj 3362 数据结构实验之图论六:村村通公路(最小生成树(裸的))
- Android Studio编译NDK app gradle配置