로딩
요청 처리 중입니다...

JAVA_LeetCode 3438_Find Valid Pair of Adjacent Digits in String

 JAVA_LeetCode 3438_Find Valid Pair of Adjacent Digits in String

JAVA_LeetCode 3438_Find Valid Pair of Adjacent Digits in String 풀이 class Solution { public String findValidPair(String s) { // hashmap으로 key-value로 숫자를 체크하고, 반복해서 앞뒤가 다른지 확인하면서 map의 value와 s의 비교 숫자가 같은 경우 현재 위치의 문자열을 반환한다. HashMap map = new HashMap(); char ch; for(int i = 0; i < s.length(); i++){ ch = s.charAt(i); map.put(ch, map.getOrDefault(ch, 0) + 1); } for(int i = 1; i < s.length(); i++){ if(s.charAt(i) == s.charAt(i - 1)) continue; if(map.get(s.charAt(i)) == s.charAt(...