首页 > 其他 > 详细

[LeetCode] 927. Three Equal Parts 三个相等的部分

时间:2019-12-27 15:11:07      阅读:126      评论:0      收藏:0      [点我收藏+]



Given an array?A?of?0s and?1s, divide the array into 3 non-empty parts such that all of these parts represent the same binary value.

If it is possible, return?any?[i, j]?with?i+1 < j, such that:

  • A[0], A[1], ..., A[i]?is the first part;
  • A[i+1], A[i+2], ..., A[j-1]?is the second part, and
  • A[j], A[j+1], ..., A[A.length - 1]?is the third part.
  • All three parts have equal binary value.

If it is not possible, return?[-1, -1].

Note that the entire part is used when considering what binary value it represents.? For example,?[1,1,0]?represents?6?in decimal,?not?3.? Also, leading zeros are allowed, so?[0,1,1]?and?[1,1]?represent the same value.

Example 1:

Input: [1,0,1,0,1]
Output: [0,3]

Example 2:

Input: [1,1,0,1,1]
Output: [-1,-1]

Note:

  1. 3 <= A.length <= 30000
  2. A[i] == 0?or?A[i] == 1



Github 同步地址:

https://github.com/grandyang/leetcode/issues/927



参考资料:

https://leetcode.com/problems/three-equal-parts/



LeetCode All in One 题目讲解汇总(持续更新中...)

[LeetCode] 927. Three Equal Parts 三个相等的部分

原文:https://www.cnblogs.com/grandyang/p/12107091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!