Checking if two strings are permutations of each other

前端 未结 30 1091
感情败类
感情败类 2020-12-05 08:19

How to determine if two strings are permutations of each other

30条回答
  •  孤街浪徒
    2020-12-05 08:56

        String str= "abcd";
        String str1 ="dcazb";
        int count=0;
    
        char s[]= str.toCharArray();
        char s1[]= str1.toCharArray();
    
        for(char c:s)
        {
            count = count+(int)c ;
        }
    
        for(char c1:s1)
        {
            count=count-(int)c1;
    
        }
    
        if(count==0)
        System.out.println("String are Anagram");
        else
        System.out.println("String are not Anagram");
    
    }
    

提交回复
热议问题