Algorithm/LeetCode
-
[string] most common wordAlgorithm/LeetCode 2025. 3. 9. 11:28
✅ Problemhttps://leetcode.com/problems/most-common-word/description/ ✅ Approach & Solution방식)더보기값 필터링 우선 수행하여 비교 대상 개수 줄이기banned에 포함되지 않는 값들에 대해서만 등장 횟수 계산Set의 contains() 사용Map을 사용해 정렬class Solution { public String mostCommonWord(String paragraph, String[] banned) { // symbol 제외한 대상 문자열만 뽑아내기 String[] words = paragraph.replaceAll("\\W+", " ").toLowerCase().split(" "); // ..
-
[string] reorder data in log filesAlgorithm/LeetCode 2025. 3. 9. 10:12
✅ Problemhttps://leetcode.com/problems/reorder-data-in-log-files/description/ ✅ Approach & Solution방식)더보기문제 조건로그의 가장 앞부분은 식별자로서, 순서에 영향을 끼치지 않는다.문자로 구성된 로그가 숫자 로그보다 앞에 오며, 문자 로그는 사전순으로 한다.문자가 동일한 경우에는 식별자순으로 한다.숫자 로그는 입력 순서대로 한다.풀이로그 나누기 (문자 로그, 숫자 로그)로그 정렬 (문자 로그만 정렬 수행)로그 합친 후 반환class Solution { public String[] reorderLogFiles(String[] logs) { List digitLogs = new ArrayList(); ..
-
[string] valid palindromeAlgorithm/LeetCode 2025. 3. 8. 11:05
✅ Problemhttps://leetcode.com/problems/valid-palindrome/description/ ✅ Approach & Solution방식)더보기주어진 문자열만 사용해 비교Character 클래스의 isLetterOrDigit(), toLowerCase()String 클래스의 charAt()투 포인터 사용해 문자열의 앞, 뒤 비교 class Solution { public boolean isPalindrome(String s) { // 조건 // 대소문자 상관 X // 문자 or 숫자 // 앞에서 읽었을 때, 뒤에서 읽었을 때 동일 boolean result = true; int start = 0;..