leetcode 1480
-
我的
class Solution:
def runningSum(self, nums: List[int]) -> List[int]:
sums = []
tmp = 0
for i in range(len(nums)):
tmp += nums[i]
sums.append(tmp)
return sums -
别人的解法
class Solution:
def runningSum(self, nums):
newnums = nums
for i in range(1,len(nums)):
newnums[i] = newnums[i-1] + nums[i]
return newnums
作者:superpangbao-m
链接:https://leetcode-cn.com/problems/running-sum-of-1d-array/solution/python3-by-superpangbao-m/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
leetcode 1672
-
我的
class Solution:
def maximumWealth(self, accounts: List[List[int]]) -> int:
sums = []
for i in range(len(accounts)):
for j in range(len(accounts)):
sums.append(sum(accounts[j]))
return max(sums) -
其他作者的 一行简洁代码
class Solution:
def maximumWealth(self, accounts: List[List[int]]) -> int:
return max(sum(accounts[i]) for i in range(len(accounts)))
作者:JamLeon
链接:https://leetcode-cn.com/problems/richest-customer-wealth/solution/yi-xing-dai-ma-si-lu-jian-dan-xing-neng-iwjw7/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
35
- 我的
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
if nums[-1]<target:
return len(nums)
if nums[0]>target:
return 0
else:
for i in range(len(nums)):
if (nums[i] == target):
return nums.index(target)
if (nums[i]<target) & (nums[i+1]>target):
return i+1 - 优秀答案
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
# 不管这个数在不在里面,直接append
nums.append(target)
# 然后再排序
nums.sort()
# 最后返回查找的index
return nums.index(target)
作者:nbcoder
链接:https://leetcode-cn.com/problems/search-insert-position/solution/pythonnei-zhi-fang-fa-chao-jian-dan-by-ljzecg/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。