题解 | #提取不重复的整数#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
原理
去重 + 反转
思考
记录一下其他思路:哈希表存储数字是否出现过的状态
hash code
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
int main(){
int num;
cin>>num;
unordered_map<int,bool> hashtable;
int sum=0,a;//a保存每次的末尾数字
while(num!=0){
int a=num%10;
if(!hashtable[a]){
hashtable[a]=true;
sum=sum*10+a;//重点 适用于从数字最大位开始出现的情况
}
num/=10;
}
cout<<sum;
}my code
str = input()
str = str[::-1]
ss = ''
for i in str:
if ss.find(i) == -1:
ss += i
print(ss)