Skip to content

Commit b8755f9

Browse files
solves #2733: Neither Minimum nor Maximum in java
1 parent f1e6b17 commit b8755f9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LeetCode Algorithms
22

33
![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg)
4-
![problems-solved-java](https://img.shields.io/badge/Java-664/2813-1abc9c.svg)
4+
![problems-solved-java](https://img.shields.io/badge/Java-674/2813-1abc9c.svg)
55
![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg)
66
![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg)
77
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
@@ -831,7 +831,7 @@
831831
| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | |
832832
| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | |
833833
| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | |
834-
| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | | |
834+
| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java ) | |
835835
| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | | |
836836
| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | | |
837837
| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | | |

src/NeitherMinimumNorMaximum.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://leetcode.com/problems/neither-minimum-nor-maximum
2+
// T: O(1)
3+
// S: O(1)
4+
5+
public class NeitherMinimumNorMaximum {
6+
public int findNonMinOrMax(int[] nums) {
7+
if (nums.length < 3) return -1;
8+
final int max = Math.max(nums[0], nums[1]);
9+
final int min = Math.min(nums[0], nums[1]);
10+
11+
if (nums[2] < min) return min;
12+
else if (nums[2] < max) return nums[2];
13+
return max;
14+
}
15+
}

0 commit comments

Comments
 (0)