Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static String encode(String word) {
- char[] charArray = word.toLowerCase().toCharArray();
- Set<Character> set = new HashSet<>();
- //ArrayList<Character> array = new ArrayList<>();
- StringBuilder result = new StringBuilder();
- for (char c : charArray) {
- if (set.contains(c)) {
- result.append(")");
- }
- else {
- result.append("(");
- }
- set.add(c);
- }
- /* for (int i = 0; i < charArray.length; i++) {
- if (!array.contains(charArray[i])) {
- result.append("(");
- } else {
- result.append(")");
- }
- }*/
- return result.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement