标签:注意事项 color dig solution int ble ram render not
反转一个只有3位数的整数。
样例 1:
输入: number = 123
输出: 321
样例 2:
输入: number = 900
输出: 9
你可以假设输入一定是一个只有三位数的整数,这个整数大于等于100,小于1000。
class Solution { public: /** * @param number: A 3-digit number. * @return: Reversed number. */ int reverseInteger(int number) { // write your code here int a=0,b=0,c=0,reverse=0; a = number/100; //百位 b = (number-a*100)/10; //十位 c = number-a*100-b*10; //个位 if(a!=0) reverse += a; if(b!=0) reverse += b*10; if(c!=0) reverse += c*100; return reverse; } };
标签:注意事项 color dig solution int ble ram render not
原文地址:https://www.cnblogs.com/tqing/p/11618798.html