diff --git a/15/JiYongKim/LeetCode.md b/15/JiYongKim/LeetCode.md new file mode 100644 index 00000000..42e4e1cb --- /dev/null +++ b/15/JiYongKim/LeetCode.md @@ -0,0 +1,37 @@ +# Sliding window 문제 + +- [219. Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii/) + +- [643. Maximum Average Subarray I](https://leetcode.com/problems/maximum-average-subarray-i/) + +
+ 982269. Find the K-Beauty of a Number + +- 982269. Find the K-Beauty of a Number + + ```java + class Solution { + public int divisorSubstrings(int num, int k) { + + String str = String.valueOf(num); + int result = 0; + + for (int i = 0; i + k - 1< str.length(); i++) { + String s = str.substring(i, i + k); + int divisor = Integer.parseInt(s); + if(divisor !=0 && num%divisor == 0) result++; + } + + return result; + } + } + ``` +
+ +- [1763. Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring/) + +- [1876. Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/) + +- [1984. Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores/) + +- [보석 쇼핑](https://programmers.co.kr/learn/courses/30/lessons/67258) \ No newline at end of file diff --git a/15/JiYongKim/SlidingWindow_TwoPointer.md b/15/JiYongKim/SlidingWindow_TwoPointer.md new file mode 100644 index 00000000..fafe6357 --- /dev/null +++ b/15/JiYongKim/SlidingWindow_TwoPointer.md @@ -0,0 +1,68 @@ +## Sliding Window Algorithm + +윈도우 즉 일정한 범위를 가지고 있으며 이를 유지하면서 이동하는 방식의 문제 풀이에서 사용되어 질 수 있는 알고리즘 이다. + +
+ +< 언제 사용할까? > + +- 배열이나 리스트의 고정된 크기 즉 윈도우 크기가 정해졌을때 사용하며 유용하다. + +
+ +< 사용 예시 > + +문제 : 연속된 3수의 최대값을 찾는 문제 + +
+ +스크린샷 2022-07-05 오후 8 13 37 + +1) 크기가 3인 윈도우 생성 + +2) 한칸씩 윈도우를 이동하면서 3수의 합을 계산 + +
+ +* * * +
+ +## 투포인터 + +배열에 순차적으로 접근해야 할 때 **두 개의 점의 위치를 기록하면서 처리**하는 알고리즘이다. + +
+ +< 언제 사용할까? > + +- 배열에서 두개의 지점의 위치 변동 즉 두개의 지점 비교가 필요할 경우 유용하다. + +
+ +<사용 예시> + +문제 : 부분 배열의 합이 M인 경우의 수를 반환하라. + +
+ +스크린샷 2022-07-05 오후 8 13 43 + +1) 포인터 first 와 second 생성 + +2) first 유지 , second 증가 하며 부분 배열 합값 확인 + +3) 합이 M보다 + +- 크면 first ++ +- 작으면 second ++ +- 동일하면 result + = 1 + +
+ +* * * + +
+ +## 투 포인터 vs 슬라이딩 윈도우 + +스크린샷 2022-07-05 오후 8 13 48