Created
November 19, 2018 15:22
-
-
Save minikuma/9036ba2f64d81673f900bf7e454f7e7b to your computer and use it in GitHub Desktop.
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 Permutation { | |
boolean permutation(String s, String t) { | |
if (s.length() != t.length()) { | |
return false; | |
} | |
//memo 저장 공간 | |
int[] marking = new int[128]; | |
//첫 번째 문자열을 memo +1 | |
char[] s_array = s.toCharArray(); | |
for (char c : s_array) { | |
marking[c]++; | |
} | |
//이미 memo된 문자 요소와 두 번째 문자 요소 memo -1 | |
for (int i = 0; i < t.length(); i++) { | |
int c = t.charAt(i); | |
marking[c]--; | |
//음수 발생 시, 두 문자열은 같이 않음 | |
if (marking[c] < 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
public static void main(String[] args) { | |
Permutation p = new Permutation(); | |
System.out.println(p.permutation("abc", "bca")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment