题目:https://leetcode-cn.com/problems/reverse-integer/
代码:
class Solution {
public:
int reverse(int x) {
//当前值
int rev = 0;

		//被弹出的值
		int pop = 0;

		while(x!=0)
		{
			int pop = x%10;
			x = x/10;
			if(rev>INT_MAX/10||rev==INT_MAX/10&&pop > 7)
			{
				return 0;
			}

			if(rev < INT_MIN/10||rev == INT_MIN/10&&pop<-8)
			{
				return 0;
			}

			rev = rev*10 + pop;


		}

		return rev;
}

};

结果:
leetcode腾讯精选50题007

相关文章:

  • 2021-05-28
  • 2021-12-01
  • 2021-04-07
  • 2021-11-21
  • 2021-08-31
  • 2021-12-02
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2021-06-17
  • 2022-12-23
  • 2021-12-17
  • 2021-04-12
  • 2021-04-19
  • 2021-09-11
  • 2021-10-04
相关资源
相似解决方案