Skip to content

Commit e683bd1

Browse files
committed
word search / find minimum in rotated sorted array
1 parent b809b98 commit e683bd1

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# μ—°κ΄€ 링크
2+
- [문제 풀이 μŠ€μΌ€μ€„](https://github.com/orgs/DaleStudy/projects/6/views/5)
3+
- [λ‹΅μ•ˆ μ½”λ“œ μ œμΆœλ²•](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C)
4+
5+
# Problem
6+
- 문제 링크 :
7+
- 문제 이름 :
8+
- 문제 번호 :
9+
- λ‚œμ΄λ„ :
10+
- μΉ΄ν…Œκ³ λ¦¬ :
11+
12+
# 문제 μ„€λͺ…
13+
14+
15+
# 아이디어
16+
- μ–΄λ–€ λ°©λ²•μœΌλ‘œ μ ‘κ·Όν–ˆλŠ”μ§€ μ„œμˆ 
17+
- 포슀 vs μ΅œμ ν™” 아이디어 차이 λ“±
18+
- μž‘λ„μ— λŒ€ν•œ κ³ λ €
19+
20+
# βœ… μ½”λ“œ (Solution)
21+
## Linear Search
22+
```cpp
23+
class Solution {
24+
public:
25+
int findMin(vector<int>& nums) {
26+
int res = nums[0];
27+
for(int i=1;i<nums.size();i++){
28+
res = min(res, nums[i]);
29+
}
30+
return res;
31+
}
32+
};
33+
```
34+
35+
- O(n) - pass
36+
- n이 μž‘μ•„μ„œ 패슀
37+
38+
## Binary Search
39+
40+
41+
```cpp
42+
class Solution {
43+
public:
44+
int findMin(vector<int>& nums) {
45+
int left = 0, right = nums.size() - 1;
46+
47+
while (left < right) {
48+
int mid = left + (right - left) / 2;
49+
50+
if (nums[mid] > nums[right]) {
51+
left = mid + 1;
52+
} else {
53+
right = mid;
54+
}
55+
}
56+
57+
return nums[left];
58+
}
59+
};
60+
```
61+
62+
- O(log n)
63+
- The Exact Solution they want...!
64+
65+
# πŸ” μ½”λ“œ μ„€λͺ…
66+
67+
68+
# μ΅œμ ν™” 포인트 (Optimality Discussion)
69+
β€’ μ΅œμ ν™”ν•œ μ΄μœ μ™€ 원리
70+
β€’ 더 쀄일 수 μžˆλŠ” μ—¬μ§€λŠ” μžˆλŠ”κ°€?
71+
β€’ κΈ°μ‘΄ 방법 λŒ€λΉ„ μ–Όλ§ˆλ‚˜ νš¨μœ¨μ μ΄μ—ˆλŠ”μ§€
72+
73+
# πŸ§ͺ ν…ŒμŠ€νŠΈ & μ—£μ§€ μΌ€μ΄μŠ€
74+
75+
# πŸ“š κ΄€λ ¨ 지식 볡슡
76+
77+
# πŸ” 회고
78+
79+

β€Žword-search/haung921209.mdβ€Ž

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# μ—°κ΄€ 링크
2+
- [문제 풀이 μŠ€μΌ€μ€„](https://github.com/orgs/DaleStudy/projects/6/views/5)
3+
- [λ‹΅μ•ˆ μ½”λ“œ μ œμΆœλ²•](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C)
4+
5+
# Problem
6+
- 문제 링크 : https://leetcode.com/problems/word-search/submissions/1617585274/
7+
- 문제 이름 : word search
8+
- 문제 번호 : 79
9+
- λ‚œμ΄λ„ : medium
10+
- μΉ΄ν…Œκ³ λ¦¬ :
11+
12+
# 문제 μ„€λͺ…
13+
14+
15+
# 아이디어
16+
- μ–΄λ–€ λ°©λ²•μœΌλ‘œ μ ‘κ·Όν–ˆλŠ”μ§€ μ„œμˆ 
17+
- 포슀 vs μ΅œμ ν™” 아이디어 차이 λ“±
18+
- μž‘λ„μ— λŒ€ν•œ κ³ λ €
19+
20+
# βœ… μ½”λ“œ (Solution)
21+
```cpp
22+
23+
class Solution {
24+
public:
25+
bool dfs(int i,int j,int count,vector<vector<char>>& board,string word){
26+
if(word.length()==count) return true;
27+
28+
if(i<0 || i>=board.size() || j<0 || j>=board[0].size() || board[i][j] != word[count])
29+
return false;
30+
31+
32+
33+
char temp = board[i][j];
34+
board[i][j] = ' ';
35+
36+
37+
bool ans = dfs(i-1,j,count+1,board,word) ||
38+
dfs(i+1,j,count+1,board,word) ||
39+
dfs(i,j-1,count+1,board,word) ||
40+
dfs(i,j+1,count+1,board,word);
41+
42+
board[i][j] = temp;
43+
return ans;
44+
}
45+
46+
bool exist(vector<vector<char>>& board, string word){
47+
int n = board.size();
48+
int m = board[0].size();
49+
50+
for(int i=0;i<n;i++){
51+
for(int j=0;j<m;j++){
52+
if(board[i][j]==word[0] && dfs(i,j,0,board,word)){
53+
return true;
54+
}
55+
}
56+
}
57+
58+
return false;
59+
}
60+
};
61+
```
62+
# πŸ” μ½”λ“œ μ„€λͺ…
63+
64+
65+
# μ΅œμ ν™” 포인트 (Optimality Discussion)
66+
β€’ μ΅œμ ν™”ν•œ μ΄μœ μ™€ 원리
67+
β€’ 더 쀄일 수 μžˆλŠ” μ—¬μ§€λŠ” μžˆλŠ”κ°€?
68+
β€’ κΈ°μ‘΄ 방법 λŒ€λΉ„ μ–Όλ§ˆλ‚˜ νš¨μœ¨μ μ΄μ—ˆλŠ”μ§€
69+
70+
# πŸ§ͺ ν…ŒμŠ€νŠΈ & μ—£μ§€ μΌ€μ΄μŠ€
71+
72+
# πŸ“š κ΄€λ ¨ 지식 볡슡
73+
74+
# πŸ” 회고
75+
76+

0 commit comments

Comments
Β (0)