牛牛是一位喜欢收集石头的小朋友。他有一天在田地里发现了一堆石头,每块石头都有一个正整数的重量。牛牛想要计算所有子区间的重量范围之和。 一个子区间是指原始区间中的一段连续的石头序列。重量范围是指子区间中的最大重量与最小重量之间的差值。 请你帮助牛牛计算所有子区间的重量范围之和。
示例1
输入
[1, 3, 3]
输出
4
说明
[1],差值为0
[3],差值为0
[3],
差值为0
[1,3],
差值为2
[3,3],
差值为0
[1,3,3],
差值为2
备注:
1 0
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ public int sumSubarrayRanges (int[] stones) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型vector * @return int整型 */ int sumSubarrayRanges(vector
& stones) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param stones int整型一维数组 # @return int整型 # class Solution: def sumSubarrayRanges(self , stones ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ public int sumSubarrayRanges (List
stones) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ function sumSubarrayRanges( stones ) { // write code here } module.exports = { sumSubarrayRanges : sumSubarrayRanges };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param stones int整型一维数组 # @return int整型 # class Solution: def sumSubarrayRanges(self , stones: List[int]) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ func sumSubarrayRanges( stones []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @param stonesLen int stones数组长度 * @return int整型 */ int sumSubarrayRanges(int* stones, int stonesLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param stones int整型一维数组 # @return int整型 # class Solution def sumSubarrayRanges(stones) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ def sumSubarrayRanges(stones: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ fun sumSubarrayRanges(stones: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ public int sumSubarrayRanges (int[] stones) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ export function sumSubarrayRanges(stones: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ func sumSubarrayRanges ( _ stones: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param stones int整型一维数组 * @return int整型 */ pub fn sumSubarrayRanges(&self, stones: Vec
) -> i32 { // write code here } }
[1, 3, 3]
4