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的更多相关文章

  1. [Swift]LeetCode486. 预测赢家 | Predict the Winner

    Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from eith ...

  2. leetcode486 Predict the Winner

    思路: 博弈. 实现: class Solution { public: bool PredictTheWinner(vector<int>& nums) { ][]; int n ...

随机推荐

  1. Eclipse Android 代码自动提示功能

    Eclipse Android 代码自动提示功能 Eclipse for android 实现代码自动提示智能提示功能,介绍 Eclipse for android 编辑器中实现两种主要文件 java ...

  2. requests beautifulsoup

    requests Python标准库中提供了:urllib.urllib2.httplib等模块以供Http请求,但是,它的 API 太渣了.它是为另一个时代.另一个互联网所创建的.它需要巨量的工作, ...

  3. node 一站式 学习 教程

    还是比较全面的, 包括了 : monogoDB的安装 使用 , 各种插件, 中间件的介绍, 路由的介绍, 各种数据库框架的介绍, 测试介绍;  掌握后应该可以开发一个中型的程序, 大型程序因为有性能的 ...

  4. Java进阶知识点5:服务端高并发的基石 - NIO与Reactor模式以及AIO与Proactor模式

    一.背景 要提升服务器的并发处理能力,通常有两大方向的思路. 1.系统架构层面.比如负载均衡.多级缓存.单元化部署等等. 2.单节点优化层面.比如修复代码级别的性能Bug.JVM参数调优.IO优化等等 ...

  5. 【英语】Bingo口语笔记(85) - ain,ane读法

  6. docx转doc时,防止公式被转成图片的解决办法

    编辑社回复需要doc(Word 97-2003)格式的文档,可是将docx(Word 2007+)另存为doc格式时,发现公式被转成了图片.其实,最简单的办法就是,打个电话过去给编辑社:“大爷,拜托您 ...

  7. LeetCode Split Array into Consecutive Subsequences

    原题链接在这里:https://leetcode.com/problems/split-array-into-consecutive-subsequences/description/ 题目: You ...

  8. linux centos6.5 安装gcc-c++时出现 yum install gcc-c++ cannot find a valid baseurl for repo...

    1.输入命令:cd /etc/sysconfig/network-scripts/ 2.ls查看该文件夹下 3.vi ifcfg-eth0 按i进行编辑,添加如下两行后,esc →shift+:→wq ...

  9. webpack新版本4.12应用九(配置文件之模块(module))

    这些选项决定了如何处理项目中的不同类型的模块. module.noParse RegExp | [RegExp] RegExp | [RegExp] | function(从 webpack 3.0. ...

  10. Spring aop 记录操作日志 Aspect 自定义注解

    时间过的真快,转眼就一年了,没想到随手写的笔记会被这么多人浏览,不想误人子弟,于是整理了一个优化版,在这里感谢智斌哥提供的建议和帮助,话不多说,进入正题 所需jar包 :spring4.3相关联以及a ...