## [面试题64. 求1+2+…+n](https://leetcode-cn.com/problems/qiu-12n-lcof/)
>Easy
#### 思路
一眼看到题目就蹦出一句话,`首项加尾项乘以项数除以2` -- 等差数组求和公式。
题目要求不能使用乘除、条件语句,于是优先想到两种方案:
* 内置函数
* 位运算
挑个简单的,AC!
时间复杂度 `$ O(n) $`
空间复杂度 `$ O(n) $`
#### 代码
python3
```
class Solution:
def sumNums(self, n: int) -> int:
return sum([x for x in range(1,n+1)])
```
- 目录
- excel-sheet-column-number
- divide-two-integers
- house-robber
- fraction-to-recurring-decimal
- profile
- kids-with-the-greatest-number-of-candies
- qiu-12n-lcof
- new-21-game
- product-of-array-except-self
- minimum-depth-of-binary-tree
- univalued-binary-tree
- shun-shi-zhen-da-yin-ju-zhen-lcof
- permutations
- satisfiability-of-equality-equations
- word-ladder-ii
- ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof
- palindrome-number
- network-delay-time
- daily-temperatures
- longest-common-prefix
- sum-of-mutated-array-closest-to-target
- 周赛专题
- make-two-arrays-equal-by-reversing-sub-arrays
- check-if-a-string-contains-all-binary-codes-of-size-k
- course-schedule-iv
- cherry-pickup-ii
- maximum-product-of-two-elements-in-an-array
- maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts
- reorder-routes-to-make-all-paths-lead-to-the-city-zero
- probability-of-a-two-boxes-having-the-same-number-of-distinct-balls
- shuffle-the-array
- the-k-strongest-values-in-an-array
- design-browser-history
- paint-house-iii
- final-prices-with-a-special-discount-in-a-shop