/
githubmirror
/
interviews
Обзор
Документация
Войти
/
githubmirror
/
interviews
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
cracking-the-coding-interview/chapter-one-arrays-and-strings/Permutation.java
25 строк
477 B
Kevin Naughton Jr
finish renaming files and directories
27 мар 2018, 19:52
27 мар 2018, 19:52
ec6dfb5
Код
Авторство
О чём код?
// Given two strings, write a method to decide if one is a permutation of the other public class Permutation { public boolean permutation(String s, String t) { if(s.length() != t.length()) { return false; } int[] letters = new int[256]; char[] s_array = s.toCharArray(); for(char c : s_array) { letters[c]++; } for(int i = 0; i < t.length(); i++) { int c = (int)t.charAt(i); if(--letters[c] < 0) { return false; } } return true; } }