当前位置:网站首页>HJ9 提取不重复的整数
HJ9 提取不重复的整数
2022-07-25 22:54:00 【敏敏程序媛】
描述
输入一个 int 型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数。
保证输入的整数最后一位不是 0 。
数据范围: 1 \le n \le 10^{8} \1≤n≤108
输入描述:
输入一个int型整数
输出描述:
按照从右向左的阅读顺序,返回一个不含重复数字的新的整数
示例1
输入:9876673
输出:37689
import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
/**
*Author:向敏
*Date:2022/07/22 15:22
*/
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext())
{
int input = scanner.nextInt();
System.out.println(getInteger(input+""));
}
scanner.close();
}
//提取不重复的整数
private static String getInteger(String numStr)
{
StringBuilder builder = new StringBuilder();
HashSet<Character> set = new LinkedHashSet<>();
//把整数倒序输入链表集合中,可以去重
for (int i = numStr.length() - 1; i >= 0;i--)
{
set.add(numStr.charAt(i));
}
//把集合中的整数输入到字符串容器中
for (Character c : set)
{
builder.append(c);
}
//如果第一个字母是0
if (builder.charAt(0) == '0')
{
return builder.substring(1,builder.length());
}
return builder.toString();
}
}边栏推荐
- Tree view model example of QT
- [training day15] boring [tree DP]
- Experiment 1, experiment 2 and Experiment 3 of assembly language and microcomputer principle: branch program design / loop program design / subroutine design
- 721. Account consolidation ●●, and collection
- Recyclerview computehorizontalscrollextend computehorizontalscrollrange computehorizontalscroll for calculating the sliding distance
- Severely crack down on illegal we media operators according to law: it is urgent to purify the we media industry
- DHCP first static experiment
- 技术美术百人计划学习笔记(2)--向量
- 1000 okaleido tiger launched binance NFT, triggering a rush to buy
- Network Security Learning (11) scanning and blasting
猜你喜欢
随机推荐
Day 3 experiment
Can generic types be used in array
ribbon 执行逻辑源码解析
The difference between abstract classes and interface interfaces
[training day15] boring [tree DP]
Tree view model example of QT
We media people must have four resource tools, each of which is very practical
Vodak software: Smart City solution
Structure principle of micro ball vibration switch with chip
Document flow definition, box model related knowledge
Node.js operation database
Stack simulation queue
Why should we launch getaverse?
TFrecord写入与读取
Today, let's talk about the if branch statement of the selection structure
Severely crack down on illegal we media operators according to law: it is urgent to purify the we media industry
CUDA environment construction
1000 okaleido tiger launched binance NFT, triggering a rush to buy
Express framework
2020-09-17








![[training Day11] Calc [mathematics]](/img/a7/cbb33f0c241e1bad90a282bba990d1.png)