求1+2+3+...+n(逻辑题)

来源:互联网 发布:windows视频截gif 编辑:程序博客网 时间:2024/06/07 04:11

题目描述

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

# -*- coding:utf-8 -*-class Solution:    def Sum_Solution(self, n):        # write code here        # 等差数列题目,完全按照要求        return (pow(n, 2) + n) >> 1



0 0
原创粉丝点击