1228A Distinct Digits codeforces solution in cpp
by ujjal roy
#include<bits/stdc++.h>
using namespace std;
int me=0;
int check(int l,int r)
{
int i;
for(i=l;i<=r;i++)
{
map<int ,int> m;
int c=0;
int s=i;
while(s!=0)
{
int re=s%10;
s/=10;
m[re]++;
if(m[re]>1)
{
c=1;
break;
}
}
if(c==0)
{
me=i;
return 1;
}
}
return 0;
}
main()
{
int l,r,i,ans;
cin>>l>>r;
ans=check(l,r);
if(ans) cout<<me<<endl;
else cout<<"-1"<<endl;
return 0;
}
0 Comments