本帖最后由 bailong360 于 2019-11-3 00:15 编辑
多来几种语言测试一下- #!/usr/bin/python
- def sum(n: int) -> int:
- return n + sum(n - 1) if n > 1 else 1
-
- if __name__ == '__main__':
- print(sum(100))
复制代码
- function sum(n) {
- return n > 1 ? n + sum(n - 1) : 1;
- }
-
- console.log(sum(100));
复制代码
- fn sum(n: u32) -> u32 {
- if n > 1 {
- n + sum(n - 1)
- } else {
- 1
- }
- }
-
- fn main() {
- println!("{}", sum(100));
- }
复制代码
|