剑指offer47-求1+2+3+...+n

题目描述

求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。

示例

输入       5

返回值   15

知识点回顾

进制转化、数学

代码

# -*- coding:utf-8 -*-
class Solution:
    def Sum_Solution(self, n):
        # write code here
        return (1+n)*n/2

 

posted @ 2020-12-08 19:48  foolangirl  阅读(81)  评论(0编辑  收藏  举报