
本文共 3366 字,大约阅读时间需要 11 分钟。
������������������������������������������������������������
������������
������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������
���������������������������������������������������������������������������������������������������������������������������������������������
������������
������������������
class Solution { public int reverse(int x) { long n = 0; while (x != 0) { n = n * 10 + x % 10; // ������������������������������������ x = x / 10; // ������x��������������������� } return (int)n == n ? (int)n : 0; }}
���������������������������������������������������������������������������������������������������������������������������
������������
������������������������������������������������������int������������������������������������������������������������������������������������������������int
���������������2 147 483 647
������������������������������������7 174 836 479
���������������������int
������������
���������������������������������������������������������������return (int)n == n ? (int)n : 0;
������������������������������������������������������������������������������������������������������������������������������n���������������0���
������������������������
������������������������������������������������������������
������������������������������������������n���������int
���������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������0���������������������������������������������
���������������������������������������������������������������������������������������������
������������������������������
class Solution { public int ReverseInt(int x) { if (x < 0) throw new ArgumentException("���������������������"); long reversedNumber = 0; int maxInt = int.MaxValue; try { while (x != 0) { reversedNumber = reversedNumber * 10 + x % 10; x = x / 10; } if (reversedNumber > maxInt) { return 0; // ������int������������������������ } return (int)reversedNumber; } catch (OverflowException) { return 0; } }}
������������������
���������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������int
������������������������������������������������������������
������������������������������������������������������0������������������������
������������
���������������������������������������������������������������������������������������������������������������������������������������
������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
