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 non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i+1 < j with (A[0] + A[1] + ... + A[i] == A[i+1] + A[i+2] + ... + A[j-1] == A[j] + A[j-1] + ... + A[A.length - 1])
题目分析及思路
给定一个整数数组,若该数组能分成三个非空数组且各数组的和相等,则返回true。划分数组时不改变原数组的顺序。可以先确定数组的和是否是3的倍数,若是则获取和的1/3值存为s_t。之后遍历数组依次求和。要求先获得s_t值再获取2*s_t值。若能满足要求则返回true。
python代码
class Solution:
def canThreePartsEqualSum(self, A: List[int]) -> bool:
if sum(A) % 3 == 0:
s_t = sum(A) / 3
count, flag1, flag2 = 0, 0, 0
for i in A:
count += i
if count == s_t:
flag1 = 1
if count == 2*s_t and flag1 == 1:
flag2 = 1
if flag1 == 1 and flag2 == 1:
return True
else:
return False
else:
return False
LeetCode 1013 Partition Array Into Three Parts With Equal Sum 解题报告的更多相关文章
- 【LeetCode】1020. Partition Array Into Three Parts With Equal Sum 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- Leetcode 1013. Partition Array Into Three Parts With Equal Sum
简单题,暴力找出来就行. class Solution: def canThreePartsEqualSum(self, A: List[int]) -> bool: s = sum(A) if ...
- 【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】548. Split Array with Equal Sum 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 日期 题目地址:https://leetcode ...
- 【LeetCode】416. Partition Equal Subset Sum 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 动态规划 日期 题目地址:https://l ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 【LeetCode】109. Convert Sorted List to Binary Search Tree 解题报告(Python)
[LeetCode]109. Convert Sorted List to Binary Search Tree 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...
随机推荐
- Java驱动远程连接mongoDB(简明易懂版)
mongodb默认是不能远程连接的,而且在linux安装完你会发现,它的目录极其简单,连个配置文件都没有. 我的mongodb的版本是3.6,目前最新的.https://www.mongodb.com ...
- AYUI -AYUI风格的 超美 百度网盘8.0
2017-03-23 19:18:43 (截止到2017-3-23 20:20:33开发结束)体验地址: http://pan.baidu.com/s/1bX28H4 新增传输列表 ======== ...
- IndexedDB 教程
IndexedDB 教程 IndexedDB 是一个基于 JavaScript 的面向对象的事务型数据库.有了 LocalStorage 和 Cookies,为什么还要推出 indexedDB 呢?其 ...
- 会使用基本的Render函数后,就会想,这怎么用 v-for/v-if/v-model;我写个vue Render函数进阶
https://blog.csdn.net/wngzhem/article/details/54291024
- /usr/bin/uwsgi --http :8888 --wsgi-file wsgi.py --master --processes 4 --threads 2
/usr/bin/uwsgi --http :8888 --wsgi-file wsgi.py --master --processes 4 --threads 2 root 18756 0.0 0. ...
- 阿里巴巴Java开发手册及Java代码规约扫描eclipse和IDEA插件
<阿里巴巴Java开发手册>: https://github.com/alibaba/p3c/blob/master/%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B ...
- 使用winsw部署spring boot jar 项目
参考:用winsw让任何Windows程序都能运行为服务 简介在linux下部署springboot项目是一件很简单的事,直接后台运行就行了,最多写个shell脚本开机自启就行了.我们最近做的项目需要 ...
- laravel5.8笔记三:常用命令
创建控制器 php artisan make:controller Index/IndexController 创建模型 php artisan make:model Index/IndexContr ...
- 最简单的方式离线部署Python依赖包
最简单的方式离线部署Python依赖包 SHOW ME CODE! 打包: $ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX) $ pip wheel -r re ...
- vue重要项目的参考
https://github.com/PanJiaChen/vue-element-admin vue项目参考 重点 https://github.com/opendigg/awesome-gith ...