IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    2020 第23周 LeetCode 记录

    Yiran\'s Blog发表于 2020-06-06 13:25:41
    love 0
    1460. Make Two Arrays Equal by Reversing Sub-arrays 链接到标题 比较两个列表是否可以通过翻转等价,统计列表中字母出现的次数判断,或者可以直接排序判断。 class Solution: def canBeEqual(self, target: List[int], arr: List[int]) -> bool: c = collections.Counter(target) for a in arr: c[a] -= 1 if c[a] < 0: return False return True 1464. Maximum Product of Two Elements in an Array 链接到标题 找到数组中最大的两个数字,分别将其数值 -1 然后相乘返回。可以直接升序排序后取最后两个数字。 func maxProduct(nums []int) int { max:=0 secondMax:=0 for i:=0;i<len(nums);i++{ e:=nums[i] if e>max{ secondMax = max max = e }else if e>secondMax{ secondMax = e } } return (max-1)*(secondMax-1) } 1461.


沪ICP备19023445号-2号
友情链接