Link: https://leetcode.com/problems/neither-minimum-nor-maximum/description/ ## 思路 由于每个数字都是distinct的 所以其实我们只要看前三个数字找出排在中间的那个就好了 可以一个一个比较大小 也可以sort前三个数字 ## Code ```python= class Solution: def findNonMinOrMax(self, nums: List[int]) -> int: if len(nums)<3: return -1 currMin, currMax = nums[0], nums[0] if nums[1] > nums[0]: currMax = nums[1] else: currMin = nums[1] if currMin<nums[2]<currMax: return nums[2] elif currMin>nums[2]: return currMin else: return currMax ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up