Skip to content

Commit

Permalink
55: Re-submit
Browse files Browse the repository at this point in the history
  • Loading branch information
sankichi92 committed Dec 29, 2023
1 parent 0a2d1a6 commit 9e96fd6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions 55-find-peak-element/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ pub fn find_peak_element(mut nums: Vec<i32>) -> i32 {
let length = nums.len();
nums.insert(0, i32::MIN);
nums.push(i32::MIN);
nums
.iter()
nums.iter()
.skip(1)
.take(length)
.enumerate()
.find(|(i, num)| nums[*i] < **num && **num > nums[*i + 2])
.find(|(i, num)| nums[*i] <= **num && **num >= nums[*i + 2])
.unwrap()
.0 as i32
}
Expand All @@ -25,4 +24,9 @@ mod tests {
fn case2() {
assert_eq!(find_peak_element(vec![1, 2, 1, 3, 5, 6, 4]), 1)
}

#[test]
fn failed_case1() {
assert_eq!(find_peak_element(vec![-2147483648]), 0)
}
}

0 comments on commit 9e96fd6

Please sign in to comment.