给定一个由正整数构成的序列 ,如果其中某一个元素 满足 a_{i+1}" (),则称该元素 为数组的一个峰点;如果其中某一个元素 满足 a_i (),则称该元素 为数组的一个谷点。 你需要实现一个函数,接受的参数为一个由正整数构成的序列 ,你需要求出这个序列中峰点和谷点的总数,并作为该函数的返回值。
示例1
输入
[1,1,4,5,1,4]
输出
2
备注:
数据保证序列 中元素的数量不超过 个。
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ public int countPeakPoint (int[] a) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型vector 序列a * @return int整型 */ int countPeakPoint(vector
& a) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 求序列a中的峰、谷点的个数 # @param a int整型一维数组 序列a # @return int整型 # class Solution: def countPeakPoint(self , a ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ public int countPeakPoint (List
a) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ function countPeakPoint( a ) { // write code here } module.exports = { countPeakPoint : countPeakPoint };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 求序列a中的峰、谷点的个数 # @param a int整型一维数组 序列a # @return int整型 # class Solution: def countPeakPoint(self , a: List[int]) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ func countPeakPoint( a []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @param aLen int a数组长度 * @return int整型 */ int countPeakPoint(int* a, int aLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 求序列a中的峰、谷点的个数 # @param a int整型一维数组 序列a # @return int整型 # class Solution def countPeakPoint(a) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ def countPeakPoint(a: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ fun countPeakPoint(a: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ public int countPeakPoint (int[] a) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ export function countPeakPoint(a: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ func countPeakPoint ( _ a: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 求序列a中的峰、谷点的个数 * @param a int整型一维数组 序列a * @return int整型 */ pub fn countPeakPoint(&self, a: Vec
) -> i32 { // write code here } }
[1,1,4,5,1,4]
2