leetcode486
public class Solution {
public bool PredictTheWinner(int[] nums) {
// int n = nums.Length;
// int[,] dp = new int[n, n];
// for (int i = 0; i < n; i++) { dp[i, i] = nums[i]; }
// for (int len = 1; len < n; len++)
// {
// for (int i = 0; i < n - len; i++)
// {
// int j = i + len;
// dp[i, j] = Math.Max(nums[i] - dp[i + 1, j], nums[j] - dp[i, j - 1]);
// }
// }
// return dp[0, n - 1] >= 0;
if (nums == null) { return true; }
int n = nums.Length;
if ((n & ) == ) { return true; } // Improved with hot13399's comment.
int[] dp = new int[n];
for (int i = n - ; i >= ; i--)
{
for (int j = i; j < n; j++)
{
if (i == j)
{
dp[i] = nums[i];
}
else
{
dp[j] = Math.Max(nums[i] - dp[j], nums[j] - dp[j - ]);
}
}
}
return dp[n - ] >= ;
}
}
https://leetcode.com/problems/predict-the-winner/#/description
leetcode486的更多相关文章
- [Swift]LeetCode486. 预测赢家 | Predict the Winner
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from eith ...
- leetcode486 Predict the Winner
思路: 博弈. 实现: class Solution { public: bool PredictTheWinner(vector<int>& nums) { ][]; int n ...
随机推荐
- 数据库oracle(PGA+SGA分配机制)
一.名词解释 (1)SGA:System Global Area是Oracle Instance的基本组成部分,在实例启动时分配;系统全局域SGA主要由三部分构成:共享池.数据缓冲区.日志缓冲区. ( ...
- 你不知道的sticky
position:sticky,Chrome新版本已经做了支持.sticky的中文翻译是“粘性的”,position:sticky表现也符合这个粘性的表现.基本上,可以看出是position:rela ...
- jgit - java实现git操作
在做一个项目中需要用到远程仓库,本来想使用svn的,但是svn的java api网上的资料很少,而且与git相比,svn显得笨重且不方便,因此放弃了svn转而使用git.java git api - ...
- POJ 2954 Triangle (pick 定理)
题目大意:给出三个点的坐标,问在这三个点坐标里面的整数坐标点有多少个(不包含边上的) 匹克定理:I = (A-E) / 2 + 1; A: 表示多边形面积 I : 表示多边形内部的点的个数 E: 表示 ...
- 【学习】JennyHui学自动化测试
学习材料:虫师的Python书,乙醇的教程 Selenium 常用的键盘事件 智能等待 处理富文本框 定位 界面数据与数据库数据对比 Excel操作 下载文件 Selenium 2.0 学习笔记 == ...
- PS更换证件照颜色
PS是我们经常使用的设计软件,在生活中使用的范围也很广,但是对于普通的用户来说,也就是平时给自己的照片美化一下,还有就是做一些证件照.今天和大家分享的是更改证件照的颜色,网上可能有很多,但是个人感觉都 ...
- Python学习-list操作
Python列表(list)操作: 序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置 ...
- 利用DAC(Data-tier Application)实现数据库结构迁移
从一个存在的库,抽取其表结构,对象,权限等,再部署成一个不包含数据的"空库"的方法有很多种.如自带的Generate Scripts功能,自定义脚本提取创建脚本等. 在实际使用中, ...
- django配置静态文件
django配置静态文件 参考文章链接:http://blog.csdn.net/hireboy/article/details/8806098
- miniofs 配置使用
1. rpm // RPM 包下载 https://github.com/minio/minfs/releases/tag/RELEASE.2017-02-26T20-20-56Z // 安装 yu ...