给定一个长度为 n 的整数数组 nums 和两个正整数 l 和 r ,找出 nums 中连续、非空且其中最大元素在范围 [left,right] 内的子数组数目。 数据范围: ,
示例1
输入
[2,1,4,6,3],2,4
输出
6
示例2
输入
[2,1,4,3],2,3
输出
3
说明
[2] , [2,1] , [3]
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型ArrayList * @param l int整型 * @param r int整型 * @return int整型 */ public int countSubarray (ArrayList
nums, int l, int r) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @param l int整型 * @param r int整型 * @return int整型 */ int countSubarray(vector
& nums, int l, int r) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @param l int整型 # @param r int整型 # @return int整型 # class Solution: def countSubarray(self , nums , l , r ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ public int countSubarray (List
nums, int l, int r) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ function countSubarray( nums , l , r ) { // write code here } module.exports = { countSubarray : countSubarray };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @param l int整型 # @param r int整型 # @return int整型 # class Solution: def countSubarray(self , nums: List[int], l: int, r: int) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ func countSubarray( nums []int , l int , r int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param numsLen int nums数组长度 * @param l int整型 * @param r int整型 * @return int整型 */ int countSubarray(int* nums, int numsLen, int l, int r ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @param l int整型 # @param r int整型 # @return int整型 # class Solution def countSubarray(nums, l, r) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ def countSubarray(nums: Array[Int],l: Int,r: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ fun countSubarray(nums: IntArray,l: Int,r: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ public int countSubarray (int[] nums, int l, int r) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ export function countSubarray(nums: number[], l: number, r: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ func countSubarray ( _ nums: [Int], _ l: Int, _ r: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param l int整型 * @param r int整型 * @return int整型 */ pub fn countSubarray(&self, nums: Vec
, l: i32, r: i32) -> i32 { // write code here } }
[2,1,4,6,3],2,4
6
[2,1,4,3],2,3
3