string
-
[hash] jewels and stonesAlgorithm/LeetCode 2025. 4. 8. 09:52
✅ Problemhttps://leetcode.com/problems/jewels-and-stones/description/ ✅ Approach & Solution방식) HashSet 사용더보기class Solution { public int numJewelsInStones(String jewels, String stones) { int cnt = 0; Set jSet = new HashSet(); for (Character c : jewels.toCharArray()) { jSet.add(c); } for (Character c : stones.toCharArray()) { if (..
-
[stack] valid parenthesesAlgorithm/LeetCode 2025. 3. 23. 11:09
✅ Problemhttps://leetcode.com/problems/valid-parentheses/description/ ✅ Approach & Solution방식1) Deque 인터페이스 사용한 Stack 구현더보기플로우(, {, [ : stack push), }, ] : stack pop빈 스택인 경우 : not valid대응하는 open bracket이 아닌 경우 : not valid빈 스택이 아닌 경우 : not validclass Solution { public boolean isValid(String s) { Deque stack = new ArrayDeque(); boolean result = true; for (int i = 0; i 방식2)..
-
[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(); ..