From be32e37826f2c3416ee4eba6543db5fdbb8d040e Mon Sep 17 00:00:00 2001 From: JiYongKim Date: Tue, 5 Jul 2022 20:11:50 +0900 Subject: [PATCH 1/3] Add SlidinwWindo_TwoPointer.md --- 15/JiYongKim/SlidingWindow_TwoPointer.md | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 15/JiYongKim/SlidingWindow_TwoPointer.md diff --git a/15/JiYongKim/SlidingWindow_TwoPointer.md b/15/JiYongKim/SlidingWindow_TwoPointer.md new file mode 100644 index 00000000..9ef33c25 --- /dev/null +++ b/15/JiYongKim/SlidingWindow_TwoPointer.md @@ -0,0 +1,68 @@ +## Sliding Window Algorithm + +윈도우 즉 일정한 범위를 가지고 있으며 이를 유지하면서 이동하는 방식의 문제 풀이에서 사용되어 질 수 있는 알고리즘 이다. + +
+ +< 언제 사용할까? > + +- 배열이나 리스트의 고정된 크기 즉 윈도우 크기가 정해졌을때 사용하며 유용하다. + +
+ +< 사용 예시 > + +문제 : 연속된 3수의 최대값을 찾는 문제 + +
+ +![스크린샷 2022-07-05 오후 7.50.48.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/cc85f404-0d2d-4469-9c7c-26e7a622a1ae/스크린샷_2022-07-05_오후_7.50.48.png) + +1) 크기가 3인 윈도우 생성 + +2) 한칸씩 윈도우를 이동하면서 3수의 합을 계산 + +
+ +* * * +
+ +## 투포인터 + +배열에 순차적으로 접근해야 할 때 **두 개의 점의 위치를 기록하면서 처리**하는 알고리즘이다. + +
+ +< 언제 사용할까? > + +- 배열에서 두개의 지점의 위치 변동 즉 두개의 지점 비교가 필요할 경우 유용하다. + +
+ +<사용 예시> + +문제 : 부분 배열의 합이 M인 경우의 수를 반환하라. + +
+ +![스크린샷 2022-07-05 오후 8.01.23.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ebd30a9a-97c4-4299-b7f5-19f0a8008871/스크린샷_2022-07-05_오후_8.01.23.png) + +1) 포인터 first 와 second 생성 + +2) first 유지 , second 증가 하며 부분 배열 합값 확인 + +3) 합이 M보다 + +- 크면 first ++ +- 작으면 second ++ +- 동일하면 result + = 1 + +
+ +* * * + +
+ +## 투 포인터 vs 슬라이딩 윈도우 + +![스크린샷 2022-07-05 오후 7.53.21.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/28f9ef7d-8bd7-449c-b2ad-4f7883ee9483/스크린샷_2022-07-05_오후_7.53.21.png) \ No newline at end of file From 80e5bd7b6b8bb3ca510999eec0607b415c998ea9 Mon Sep 17 00:00:00 2001 From: JiYong Kim <81874493+JiYongKim-A@users.noreply.github.com> Date: Tue, 5 Jul 2022 20:14:28 +0900 Subject: [PATCH 2/3] Update SlidingWindow_TwoPointer.md --- 15/JiYongKim/SlidingWindow_TwoPointer.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/15/JiYongKim/SlidingWindow_TwoPointer.md b/15/JiYongKim/SlidingWindow_TwoPointer.md index 9ef33c25..fafe6357 100644 --- a/15/JiYongKim/SlidingWindow_TwoPointer.md +++ b/15/JiYongKim/SlidingWindow_TwoPointer.md @@ -16,7 +16,7 @@
-![스크린샷 2022-07-05 오후 7.50.48.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/cc85f404-0d2d-4469-9c7c-26e7a622a1ae/스크린샷_2022-07-05_오후_7.50.48.png) +스크린샷 2022-07-05 오후 8 13 37 1) 크기가 3인 윈도우 생성 @@ -45,7 +45,7 @@
-![스크린샷 2022-07-05 오후 8.01.23.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ebd30a9a-97c4-4299-b7f5-19f0a8008871/스크린샷_2022-07-05_오후_8.01.23.png) +스크린샷 2022-07-05 오후 8 13 43 1) 포인터 first 와 second 생성 @@ -65,4 +65,4 @@ ## 투 포인터 vs 슬라이딩 윈도우 -![스크린샷 2022-07-05 오후 7.53.21.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/28f9ef7d-8bd7-449c-b2ad-4f7883ee9483/스크린샷_2022-07-05_오후_7.53.21.png) \ No newline at end of file +스크린샷 2022-07-05 오후 8 13 48 From 5aece1ae0bcee0671d90b27bb580655d85712771 Mon Sep 17 00:00:00 2001 From: JiYongKim Date: Tue, 5 Jul 2022 20:16:54 +0900 Subject: [PATCH 3/3] Add LeetCode.md --- 15/JiYongKim/LeetCode.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 15/JiYongKim/LeetCode.md 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