[A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded messag]
判断一个整数是不是回文,且不用额外的空间,这个很简单,就是把一个整数翻转一下,跟itoa非常相似。直接上代码吧[A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded messag]
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0) {
return false;
}
int num = x;
int new_num = 0;
while (num) {
int tmp = num / 10;
new_num = 10 * new_num + (num - tmp * 10);
num = tmp;
}
return x == new_num;
}
};
class Solution:
# @param {integer} x
# @return {boolean}
def isPalindrome(self, x):
if x < 0:
return False
num = int(x)
new_num = 0;
while num > 0:
new_num = 10 * new_num + int(num % 10)
num = int(num / 10)
return x == new_num
[Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory]