就是把一個(gè)整數(shù)進(jìn)行反轉(zhuǎn),
LeetCode Reverse Integer
。思路:
1.注意負(fù)號的處理
2.進(jìn)行一次遍歷倒序存每一位就可以了。
實(shí)現(xiàn)代碼:
public int Reverse(int x) {var s = x.ToString();var len = s.Length;if(len == 1){return x;}var result = string.Empty;if(s[0] == '-'){result = -;for(var i = 1;i < len; i++){result += s[len-i];}}else{for(var i = 0;i < len; i++){result += s[len-i-1];}}var r = 0;Int32.TryParse(result,out r);return r;}