码迷,mamicode.com
首页 > 编程语言 > 详细

[LeetCode] Split Array with Equal Sum 分割数组成和相同的子数组

时间:2017-05-15 00:42:43      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:相同   lan   which   arrays   bsp   find   triple   subarray   equal   

 

Given an array with n integers, you need to find if there are triplets (i, j, k) which satisfies following conditions:

  1. 0 < i, i + 1 < j, j + 1 < k < n - 1
  2. Sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - 1) and (k + 1, n - 1) should be equal.

where we define that subarray (L, R) represents a slice of the original array starting from the element indexed L to the element indexed R.

Example:

Input: [1,2,1,2,1,2,1]
Output: True
Explanation:
i = 1, j = 3, k = 5. 
sum(0, i - 1) = sum(0, 0) = 1
sum(i + 1, j - 1) = sum(2, 2) = 1
sum(j + 1, k - 1) = sum(4, 4) = 1
sum(k + 1, n - 1) = sum(6, 6) = 1

Note:

  1. 1 <= n <= 2000.
  2. Elements in the given array will be in range [-1,000,000, 1,000,000].
 
 s
 
 

 

[LeetCode] Split Array with Equal Sum 分割数组成和相同的子数组

标签:相同   lan   which   arrays   bsp   find   triple   subarray   equal   

原文地址:http://www.cnblogs.com/grandyang/p/6854492.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!