
数组求和
枫流仁武
这个作者很懒,什么都没留下…
展开
-
LeetCode 18 四数之和
给定一个包含n 个整数的数组nums和一个目标值target,判断nums中是否存在四个元素 a,b,c和 d,使得a + b + c + d的值与target相等?找出所有满足条件且不重复的四元组。 结果不可重复 注意要去重 from typing import * class Solution: def fourSum(self, nums: List[int], target: int) -> List[List[int]]: res ...原创 2020-11-27 09:11:10 · 95 阅读 · 0 评论 -
LeetCode 327 区间和的个数
给定一个整数数组nums,返回区间和在[lower, upper]之间的个数,包含lower和upper。 区间和S(i, j)表示在nums中,位置从i到j的元素之和,包含i和j(i ≤ j)。 肯定是想要得到一个NlogN的方法。 这道题可以采用归并,线段树,树状数组等方法,这里给出二分搜索题解。 from typing import * import bisect class Solution: def countRangeSum(self, n...原创 2020-11-07 11:16:30 · 180 阅读 · 0 评论 -
PAT 1044 Shopping in Mars
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position ...原创 2019-06-08 16:34:30 · 118 阅读 · 0 评论