Skip to content

Commit 6c83038

Browse files
committed
update 852 java
1 parent aeb3932 commit 6c83038

File tree

2 files changed

+92
-33
lines changed

2 files changed

+92
-33
lines changed

.github/workflows/pythonapp.yml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
name: Python application
1+
# name: Python application
22

3-
on: [push]
3+
# on: [push]
44

5-
jobs:
6-
build:
5+
# jobs:
6+
# build:
77

8-
runs-on: ubuntu-latest
8+
# runs-on: ubuntu-latest
99

10-
steps:
11-
- uses: actions/checkout@v2
12-
- name: Set up Python 3.10.15
13-
uses: actions/setup-python@v1
14-
with:
15-
python-version: 3.10.15
16-
- name: Install dependencies
17-
run: |
18-
python -m pip install --upgrade pip
19-
#pip install -r requirements.txt
20-
- name: Lint with flake8
21-
run: |
22-
pip install flake8
23-
# stop the build if there are Python syntax errors or undefined names
24-
#flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
25-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
26-
#flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
27-
- name: Run pytest
28-
run: |
29-
pip install pytest
30-
python script/get_review_list.py
31-
- name: List LC
32-
run: |
33-
pip install pytest
34-
#pytest
35-
bash script/list_leetcode_solutions_by_type.sh
36-
bash script/get_company_LC.sh google output1.txt
10+
# steps:
11+
# - uses: actions/checkout@v2
12+
# - name: Set up Python 3.10.15
13+
# uses: actions/setup-python@v1
14+
# with:
15+
# python-version: 3.10.16
16+
# - name: Install dependencies
17+
# run: |
18+
# python -m pip install --upgrade pip
19+
# #pip install -r requirements.txt
20+
# - name: Lint with flake8
21+
# run: |
22+
# pip install flake8
23+
# # stop the build if there are Python syntax errors or undefined names
24+
# #flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
25+
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
26+
# #flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
27+
# - name: Run pytest
28+
# run: |
29+
# pip install pytest
30+
# python script/get_review_list.py
31+
# - name: List LC
32+
# run: |
33+
# pip install pytest
34+
# #pytest
35+
# bash script/list_leetcode_solutions_by_type.sh
36+
# bash script/get_company_LC.sh google output1.txt

leetcode_java/src/main/java/LeetCodeJava/BinarySearch/PeakIndexInAMountainArray.java

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,66 @@ else if (arr[mid] < arr[mid + 1]) {
136136
// mountain array)
137137
}
138138

139-
// V1
139+
// V1-1
140+
// https://leetcode.com/problems/peak-index-in-a-mountain-array/editorial/
141+
// IDEA : LINEAR SCAN
142+
public int peakIndexInMountainArray_1_1(int[] arr) {
143+
int i = 0;
144+
while (arr[i] < arr[i + 1]) {
145+
i++;
146+
}
147+
return i;
148+
}
149+
150+
// V1-2
151+
// https://leetcode.com/problems/peak-index-in-a-mountain-array/editorial/
152+
// IDEA : Binary Search
153+
public int peakIndexInMountainArray_1_2(int[] arr) {
154+
int l = 0, r = arr.length - 1, mid;
155+
while (l < r) {
156+
mid = (l + r) / 2;
157+
if (arr[mid] < arr[mid + 1])
158+
l = mid + 1;
159+
else
160+
r = mid;
161+
}
162+
return l;
163+
}
140164

141165
// V2
166+
// https://leetcode.com/problems/peak-index-in-a-mountain-array/solutions/6237785/binary-search-by-retr0sec-si97/
167+
// IDEA: BINARY SEARCH
168+
public int peakIndexInMountainArray_2(int[] arr) {
169+
170+
int left = 0;
171+
int right = arr.length - 1;
172+
173+
while (left <= right) {
174+
int mid = left + (right - left) / 2;
175+
if (mid >= 1 && mid <= arr.length - 1 && arr[mid] < arr[mid - 1]) {
176+
right = mid - 1;
177+
} else {
178+
left = mid + 1;
179+
}
180+
}
181+
return right;
182+
}
183+
184+
// V3
185+
// https://leetcode.com/problems/peak-index-in-a-mountain-array/solutions/6235886/check-out-this-solution-if-you-want-most-si4s/
186+
// IDEA: BINARY SEARCH
187+
public int peakIndexInMountainArray(int[] arr) {
188+
int start = 0;
189+
int end = arr.length - 1;
190+
while (start != end) {
191+
int mid = start + (end - start) / 2;
192+
if (arr[mid] < arr[mid + 1]) {
193+
start = mid + 1;
194+
} else if (arr[mid] > arr[mid + 1]) {
195+
end = mid;
196+
}
197+
}
198+
return start;
199+
}
200+
142201
}

0 commit comments

Comments
 (0)