小white刷题记——LeetCodeHot100_7

该文章讨论了一种将整数转换为字符串进行反转的方法,处理过程中考虑了int类型的边界值限制,如2147483647和-2147483648。在反转后,会检查结果是否超出int的范围,如果超出则返回0。这种方法适用于解决LeetCode中的整数反转问题。
摘要由CSDN通过智能技术生成

 读题心路历程:题读完,感觉好像也没那么难,我直接把int类型转换为string类型,然后reverse一下,再判断一下字符串前面是不是0,感觉就可以了。这个题可能复杂一点的就是int边界值的限制了。参考leetcode题解:图解 7. 整数反转 - 整数反转 - 力扣(LeetCode)

 int reverse(int x) {
        int ans = 0;
	    while (x!=0)
	    {
            int tmp = x % 10;
            if (ans > 214748364 || (ans == 214748364 && tmp > 7))
            {
                return 0;
            }
            if (ans < -214748364 || (ans == -214748364 && tmp < -8)) {
                return 0;
            }
            ans = ans * 10 + tmp;
            x = x / 10;
	    }
        return ans;
    }

“ # 设置按钮的背景颜色 self.m_button1.SetBackgroundColour('#0a74f7') self.m_button1.SetForegroundColour('white') self.m_button2.SetBackgroundColour('#0a74f7') self.m_button2.SetForegroundColour('white') self.m_button3.SetBackgroundColour('#0a74f7') self.m_button3.SetForegroundColour('white') self.m_button4.SetBackgroundColour('#238E23') self.m_button4.SetForegroundColour('white') self.m_button5.SetBackgroundColour('#238E23') self.m_button5.SetForegroundColour('white') self.m_button6.SetBackgroundColour('#238E23') self.m_button6.SetForegroundColour('white') self.m_button7.SetBackgroundColour('#6F4242') self.m_button7.SetForegroundColour('white') self.m_button8.SetBackgroundColour('#6F4242') self.m_button8.SetForegroundColour('white') self.m_button9.SetBackgroundColour('#6F4242') self.m_button9.SetForegroundColour('white') self.m_button10.SetBackgroundColour('#8E6B23') self.m_button10.SetForegroundColour('white') self.m_button11.SetBackgroundColour('#8E6B23') self.m_button11.SetForegroundColour('white') self.m_button12.SetBackgroundColour('#8E6B23') self.m_button12.SetForegroundColour('white') self.m_button13.SetBackgroundColour('#8E6B23') self.m_button13.SetForegroundColour('white') self.m_button14.SetBackgroundColour('#545454') self.m_button14.SetForegroundColour('white') self.m_button15.SetBackgroundColour('#545454') self.m_button15.SetForegroundColour('white') self.m_button16.SetBackgroundColour('#545454') self.m_button16.SetForegroundColour('white') self.m_panel1.SetBackgroundColour('white') # 设置面板的背景颜色”逐行解释代码
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值