We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
反转一个只有 3 位数的整数
123 反转之后是 321。 900 反转之后是 9。
009
9
这是最简单,最容易想到的答案:
parseInt
const reverseInteger = function(number) { return +[...number.toString()].reverse().join(''); };
const reverseInteger = function (number) { return parseInt(number%10)*100+parseInt((number%100)/10)*10+parseInt(number/100)*1 }
通过取余操作,个位转百位,十位转十位,百位转个位。
比如:123=>300+20+1,输出321
const reverseInteger = function(number) { var str = number.toString(); // 转字符 return parseInt(str.charAt(2) + str.charAt(1) + str.charAt(0)); // 取对应位置字符,拼接成新的字符串 };
博客链接
The text was updated successfully, but these errors were encountered:
No branches or pull requests
博客链接
# 反转一个 3 位整数
# 描述:
反转一个只有 3 位数的整数
# 样例:
123 反转之后是 321。 900 反转之后是 9。
# 题目分析:
009
这种形式需要转为9
# 转数组操作:
这是最简单,最容易想到的答案:
parseInt
等也是可以的)# 取余数,逐个颠倒
通过取余操作,个位转百位,十位转十位,百位转个位。
比如:123=>300+20+1,输出321
# 拼接字符串:
# 点个Star支持我一下~
博客链接
The text was updated successfully, but these errors were encountered: