Leetcode 1013. Partition Array Into Three Parts With Equal Sum
简单题,暴力找出来就行.
class Solution:
def canThreePartsEqualSum(self, A: List[int]) -> bool:
s = sum(A)
if s % 3 > 0:
return False
s /= 3
size = len(A)
t = 0
a, b = -1, -1
for i in range(size):
t += A[i]
if t == s:
a = i
break
t = 0
for j in range(size - 1, -1, -1):
t += A[j]
if t == s:
b = j
break
if a == -1 or b == -1 or a + 1 >= b:
return False
return True
Leetcode 1013. Partition Array Into Three Parts With Equal Sum的更多相关文章
- LeetCode 1013 Partition Array Into Three Parts With Equal Sum 解题报告
题目要求 Given an array A of integers, return true if and only if we can partition the array into three ...
- 【LeetCode】1020. Partition Array Into Three Parts With Equal Sum 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】1020. Partition Array Into Three Parts With Equal Sum
题目如下: Given an array A of integers, return true if and only if we can partition the array into three ...
- [Swift]LeetCode1013. 将数组分成和相等的三个部分 | Partition Array Into Three Parts With Equal Sum
Given an array A of integers, return true if and only if we can partition the array into three non-e ...
- Partition Array Into Three Parts With Equal Sum LT1013
Given an array A of integers, return true if and only if we can partition the array into three non-e ...
- [LeetCode] 915. Partition Array into Disjoint Intervals 分割数组为不相交的区间
Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...
- LeetCode 1043. Partition Array for Maximum Sum
原题链接在这里:https://leetcode.com/problems/partition-array-for-maximum-sum/ 题目: Given an integer array A, ...
- 698. Partition to K Equal Sum Subsets
Given an array of integers nums and a positive integer k, find whether it's possible to divide this ...
- [LeetCode] 416. Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
随机推荐
- python的变量类型(Day6)
Python的变量类型 变量可以指定不同的数据类型,这些变量可以存储整数,小数或字符. 变量赋值 Python 中的变量赋值不需要类型声明 等号(=)用来给变量赋值,等号左边为变量值,等号右边是存储在 ...
- day4-递归
递归 特点 递归算法是一种直接或者间接地调用自身算法的过程.在计算机编写程序中,递归算法对解决一大类问题是十分有效的,它往往使算法的描述简洁而且易于理解. 递归算法解决问题的特点: (1) 递归就是在 ...
- 本地连不上远程mysql数据库(2)
Host is not allowed to connect to this MySQL server解决方法 今天在ubuntu上面装完MySQL,却发现在本地登录可以,但是远程登录却报错Host ...
- curl简介、安装及使用
目录 curl简介 curl安装 curl使用 curl简介 curl是Linux下一个强大的文件传输工具,它利用URL语法在命令行方式下工作,支持文件上传和下载. curl安装 Ubuntu系统键入 ...
- GIT使用—创建一个版本库
一.GIT命令行 [root@localhost ~]# git usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] ...
- 20145201《Java程序设计》第1次实验报告
实验内容 一.命令行下java程序开发 1.建立Code目录,输入mkdir 20145201命令建立实验目录,并使用dir命令查看目录建立情况. 运行结果如图 2.进入实验目录,输入mkdir ex ...
- 什么是“欧几里德范数”(Euclidean norm)?
x是n维向量(x1,x2,…,xn),||x||=根号(|x1|方+|x2|方+…+|xn|方) 补充:开平方,跟几何一样
- Linux下挂载windows的共享文件夹
环境说明: 由于领导要求:现需要将某Linux服务器下的一个文件移动到某windows服务器下(服务器均在机房托管,要远程操作) 由于操作为一次性,则决定在windows下建立一个共享文件夹,linu ...
- CentOS 7 源码安装Ansible 2.x
1.安装Python 3.x环境 [root@ansible ~]# yum install -y python36 python36-pip git [root@ansible ~]# ln -s ...
- 并发-CountDownLatch、CyclicBarrier和Semaphore
CountDownLatch.CyclicBarrier和Semaphore 参考: http://www.cnblogs.com/dolphin0520/p/3920397.html https:/ ...