题解 | #求1+2+3+...+n#

求1+2+3+...+n

https://www.nowcoder.com/practice/7a0da8fc483247ff8800059e12d7caf1

class Solution:
    def binmulti(self , n: int , m: int):
        if m == 0:
            return 0
        if m == 1:
            return n
        temp =  m & 1
        m -= temp
        n <<= 1
        m >>= 1
        return (m and self.binmulti(n , m)) + (temp and (n >> 1))
    def Sum_Solution(self , n: int) -> int:
        # write code here
        return self.binmulti(n , n + 1) >> 1

全部评论

相关推荐

码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务