Guest User

Untitled

a guest
Nov 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public class Permutation {
  2. boolean permutation(String s, String t) {
  3. if (s.length() != t.length()) {
  4. return false;
  5. }
  6. //memo 저장 공간
  7. int[] marking = new int[128];
  8. //첫 번째 문자열을 memo +1
  9. char[] s_array = s.toCharArray();
  10. for (char c : s_array) {
  11. marking[c]++;
  12. }
  13. //이미 memo된 문자 요소와 두 번째 문자 요소 memo -1
  14. for (int i = 0; i < t.length(); i++) {
  15. int c = t.charAt(i);
  16. marking[c]--;
  17. //음수 발생 시, 두 문자열은 같이 않음
  18. if (marking[c] < 0) {
  19. return false;
  20. }
  21. }
  22. return true;
  23. }
  24. public static void main(String[] args) {
  25. Permutation p = new Permutation();
  26. System.out.println(p.permutation("abc", "bca"));
  27. }
  28. }
Add Comment
Please, Sign In to add comment