Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. 用取模方式取x的个位数,直到x为0,同时更新返回值ret。 class Solution { public: int reverse(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function int ret = 0; while (x != 0) { ret *= 10; ret += (x % 10); x /= 10; } return ret; } };