-
953. Verifying an Alien Dictionary javaLeetCode_Study_Plan/Programming Skills 2022. 9. 22. 22:24
class Solution { public boolean isAlienSorted(String[] words, String order){ HashMap<String, Integer> map = new HashMap<>(); for(int i = 0; i < order.length(); i++){ map.put(String.valueOf(order.charAt(i)), i); } for(int i = 0; i < words.length - 1; i++){ for(int j = 0; j < words[i].length(); j++){ if (j >= words[i+1].length()) { return false; } if (map.get(String.valueOf(words[i].charAt(j))) == map.get(String.valueOf(words[i+1].charAt(j)))) continue; if (map.get(String.valueOf(words[i].charAt(j))) > map.get(String.valueOf(words[i+1].charAt(j)))){ return false; } break; } } return true; } }
'LeetCode_Study_Plan > Programming Skills' 카테고리의 다른 글
876. Middle of the Linked List java (0) 2022.09.24 1290. Convert Binary Number in a Linked List to Integer java (0) 2022.09.24 1309. Decrypt String from Alphabet to Integer Mapping java (0) 2022.09.22 709. To Lower Case java (0) 2022.09.22 [Programming Skills I] 이틀 뒤, 중간 점검 (2) 2022.09.21