Advertisement
unknown_0711

Untitled

Dec 3rd, 2022
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Solution {
  4. public static String hasUnique(String str) {
  5. int n = str.length();
  6. boolean count = true;
  7. int []s= new int[26];
  8. int []l= new int[26];
  9. for(int i=0;i<26;i++){
  10. s[i]=0;
  11. l[i]=0;
  12. }
  13. for(int i=0;i<n;i++){
  14. if(str.charAt(i)>='a' && str.charAt(i)<='z')s[str.charAt(i)-'a']++;
  15. }
  16. for(int i=0;i<n;i++){
  17. if(str.charAt(i)>='A' && str.charAt(i)<='Z')l[str.charAt(i)-'A']++;
  18. }
  19. for(int i=0;i<26;i++){
  20. if(s[i]>1 || l[i]>1)count=false;
  21. }
  22. if(count==true){
  23. return ("Yes");
  24. }
  25. else{
  26. return ("No");
  27. }
  28. }
  29. }
  30.  
  31. public class Main {
  32. public static void main(String[] args) {
  33. Scanner sc = new Scanner(System.in);
  34. String str = sc.nextLine();
  35. Solution Obj = new Solution();
  36. System.out.println(Obj.hasUnique(str));
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement