当前位置:网站首页>Hj9 extract non duplicate integers
Hj9 extract non duplicate integers
2022-07-25 22:58:00 【Min Min, chengxuyuan】
describe
Enter a int Type integer , Read right to left , Returns a new integer with no repeating numbers .
Ensure that the last bit of the input integer is not 0 .
Data range : 1 \le n \le 10^{8} \1≤n≤108
Input description :
Enter a int Type integer
Output description :
Read right to left , Returns a new integer with no repeating numbers
Example 1
Input :9876673
Output :37689
import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
/**
*Author: Xiang min
*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();
}
// Extract non duplicate integers
private static String getInteger(String numStr)
{
StringBuilder builder = new StringBuilder();
HashSet<Character> set = new LinkedHashSet<>();
// Input the integer in reverse order into the linked list set , You can get rid of it
for (int i = numStr.length() - 1; i >= 0;i--)
{
set.add(numStr.charAt(i));
}
// Enter the integers in the set into the string container
for (Character c : set)
{
builder.append(c);
}
// If the first letter is 0
if (builder.charAt(0) == '0')
{
return builder.substring(1,builder.length());
}
return builder.toString();
}
}边栏推荐
- CMU AI PhD 第一年总结
- Websocket summary
- Qt的TQTreeWidget控件
- Ma Tiji Wanmin hall Chef
- Deep recursion, deep search DFS, backtracking, paper cutting learning.
- Kibana~ the process number cannot be found after kibana is started in the background
- Summary of traversal methods of six sets list, set, map, queue, deque and stack
- The difference between abstract classes and interfaces
- Tree view model example of QT
- 新媒体运营策略(以小红书为例)帮助你快速掌握爆款创作方法
猜你喜欢
随机推荐
Interpretation of English terms
互联网协议之 IPFS
Can generic types be used in array
Simple setting of drop-down triangle
The new media operation strategy (taking xiaohongshu as an example) helps you quickly master the creative method of popular models
CMU AI PhD first year summary
Ssh server CBC encryption mode vulnerability (cve-2008-5161)
技术美术百人计划学习笔记(1)--基础渲染管线
ZCMU--5015: 完成任务
Qt的TQTreeWidget控件
Recommend short videos every week: more and more smart devices need collaboration, posing a greater challenge to the development of the Internet of things?
The difference between "= =" and equals
1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
Ribbon execution logic source code analysis
Code shoe set precision barrage
【自然语言处理】【向量表示】AugSBERT:改善用于成对句子评分任务的Bi-Encoders的数据增强方法
Kibana~ the process number cannot be found after kibana is started in the background
Understanding of forward proxy and reverse proxy
The difference between "rewrite" and "overload"
The difference between abstract classes and interfaces









