美文网首页
1304. Find N Unique Integers Sum

1304. Find N Unique Integers Sum

作者: 鱼欲遇雨 | 来源:发表于2020-01-21 13:18 被阅读0次

解法一

  1. 数组长度的一半
  2. 遍历[负一半,正一半] 之间
  3. 零做特殊化校验,如果是奇数,增加0, 其他的继续

解法二 数学推导

  1. 假设左边的边界为l, 右边的边界为 r
  2. 根据题意知道 r-l = 2(n-1), 同时 r = -l,知道 r = n-1 l = 1-n
  3. 所以 list(rang(1-n, n, 2))

相关文章

网友评论

      本文标题:1304. Find N Unique Integers Sum

      本文链接:https://www.haomeiwen.com/subject/uglezctx.html