-
-
Save asdw3276/f9e259ebf504db026e7d to your computer and use it in GitHub Desktop.
1.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ispermutation | |
{ | |
public static void main(String[] args) | |
{ | |
String s = ""; | |
String t = ""; | |
boolean result = ispermutation(s,t); | |
System.out.println(result); | |
} | |
public static boolean ispermutation(String s, String t) | |
{ | |
if(s.length() != t.length()) | |
return false; | |
int[] flag = new int[256]; | |
int value = 0; | |
for(int i = 0; i < s.length(); i++) | |
{ | |
value = s.charAt(i); | |
flag[value]++; | |
} | |
for(int i = 0; i < t.length(); i++) | |
{ | |
value = t.charAt(i); | |
flag[value]--; | |
} | |
for(int i = 0; i < 256; i++) | |
{ | |
if(flag[i] != 0) | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment