Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4728759

Browse files
author
applewjg
committed
FindMinimumInRotatedSortedArray
Change-Id: I0c9bc7c28cca6a725455f1c0c286e248f99779ab
1 parent2a4ee69 commit4728759

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

‎FindMinimumInRotatedSortedArray.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Author: Andy, nkuwjg@gmail.com
3+
Date: Oct 22, 2014
4+
Problem: Find Minimum in Rotated Sorted Array
5+
Difficulty: Medium
6+
Source: https://oj.leetcode.com/problems/find-minimum-in-rotated-sorted-array/
7+
Notes:
8+
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
9+
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
10+
11+
Find the minimum element.
12+
13+
You may assume no duplicate exists in the array.
14+
*/
15+
publicclassSolution {
16+
publicintfindMin(int[]num) {
17+
if (num.length ==0)return0;
18+
intleft =0,right =num.length -1;
19+
while (left <right &&num[left] >num[right]) {
20+
intmid =left + (right -left) /2;
21+
if (num[mid] >num[right])left =mid +1;
22+
elseright =mid;
23+
}
24+
returnnum[left];
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Author: Andy, nkuwjg@gmail.com
3+
Date: Oct 22, 2014
4+
Problem: Find Minimum in Rotated Sorted ArrayII
5+
Difficulty: Hard
6+
Source: https://oj.leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/
7+
Notes:
8+
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
9+
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
10+
11+
Find the minimum element.
12+
13+
The array may contain duplicates.
14+
*/
15+
16+
publicclassSolution {
17+
publicintfindMin(int[]num) {
18+
if (num.length ==0)return0;
19+
intleft =0,right =num.length -1;
20+
while (left <right &&num[left] >=num[right]) {
21+
intmid =left + (right -left) /2;
22+
if (num[mid] >num[right])left =mid +1;
23+
elseif (num[mid] <num[right])right =mid;
24+
elseleft++;
25+
}
26+
returnnum[left];
27+
}
28+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp