Love丶FFC's Blog

LintCode_naive:反转一个3位整数

2019-08-17 20:15:58
阅读:572   •   评论:3
标签:,

描述

反转一个只有3位数的整数。

Tips: 你可以假设输入一定是一个只有三位数的整数,这个整数大于等于100,小于1000。

样例

样例1

输入: number = 123
输出: 321

样例2

输入: number = 900
输出: 9

编程语言:Java

解题思想:

1.使用Java的字符串类库。

2.字符串与整型的互相转换。

3.字符串的拼接。

时间复杂度:O(1)

IDE代码如下:

  1. package Lintcode;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _37 {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int Number = scanner.nextInt();
  10. int ChangeNumber;
  11. ChangeNumber=Integer.parseInt((Number+"").charAt(2)+""+(Number+"").charAt(1)+""+(Number+"").charAt(0)+"");
  12. System.out.println(ChangeNumber);
  13. }
  14.  
  15. }

LintCode编辑器代码如下:

  1. public class Solution {
  2.  
  3. public int reverseInteger(int number) {
  4. int ChangeNumber;
  5. ChangeNumber=Integer.parseInt((number+"").charAt(2)+""+(number+"").charAt(1)+""+(number+"").charAt(0)+"");
  6. return ChangeNumber;
  7. }
  8. }

评论板

共有 3 条评论

  1. Jorcift

    Drug resistance and the resulting ineffectiveness of the drug treatment are responsible for up to 90 of the cancer related deaths 3 7 priligy in usa

  2. intuido

    The patients in SOFT who received chemotherapy had received it previously, remained premenopausal, and underwent randomization within 8 months after completing chemotherapy, once a premenopausal estradiol level had been confirmed by a local laboratory side effects of viagra pills

  3. intuido

    Ecstasy had terrible reliability and it s the same with Molly does viagra stop you coming

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:510850