''' 题目描述 求1+2+3+...+n, 要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C) 对数值型变量左移或者右移1位,分别表示将原始数值乘2或者除2 ''' # -*- coding:utf-8 -*- class Solution: def Sum_Solution(self, n): # write code here if n==0: return 0 out=n**2 out+=n out=out>>1 return out if __name__=='__main__': print(Solution().Sum_Solution(5))
python 求1+2+3+...+n
猜你喜欢
转载自blog.csdn.net/WYXHAHAHA123/article/details/89301066
今日推荐
周排行