洞察探讨小游戏SDK接入的最佳实践以及对企业跨平台开发的优势
688
2022-08-25
LeetCode-852. Peak Index in a Mountain Array
Let's call an array A a mountain if the following properties hold:
A.length >= 3There exists some0 < i < A.length - 1 such thatA[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]
Given an array that is definitely a mountain, return any i such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1].
Example 1:
Input: [0,1,0]Output: 1
Example 2:
Input: [0,2,1,0]Output: 1
Note:
3 <= A.length <= 100000 <= A[i] <= 10^6A is a mountain, as defined above.
题解:
不加int n = A.size() 并判断 n == 0 的话98%,但是为严谨起见加入判断较好。
毕竟以后公司的工程代码的严谨性和规范性最重要。
慢慢培养自己的严谨代码风格吧~
readability counts。
class Solution {public: int peakIndexInMountainArray(vector
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~