Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@asdw3276
Created June 17, 2014 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asdw3276/f9e259ebf504db026e7d to your computer and use it in GitHub Desktop.
Save asdw3276/f9e259ebf504db026e7d to your computer and use it in GitHub Desktop.
1.3
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