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. jQUery 样式操作

    一.css样式操作的方法: 1..css("样式"):获得样式值,比如$("input").css("color")  获得input中字体 ...

  2. 本地动态SQL

    (转自:http://blog.itpub.net/26622598/viewspace-718134) 一.什么是动态SQL 大多数PL/SQL都做着一件特殊的结果可预知的工作.例如,一个存储过程可 ...

  3. PostgreSQL归档日志 手动触发归档 select pg_switch_xlog()

    (转,做记录) 一 环境信息--1.1 PostgreSQL 版本 9.3.0 --1.2 postgresql.conf wal_level = hot_standbyarchive_mode = ...

  4. javascript 继承的两种方式

    js中继承可以分为两种:对象冒充和原型链方式 一.对象冒充包括三种:临时属性方式.call()及apply()方式1.临时属性方式 代码如下: function Person(name){     t ...

  5. 谈谈Java基础数据类型

    Java的基本数据类型 类型 意义 取值 boolean 布尔值 true或false byte 8位有符号整型 -128~127 short 16位有符号整型 -pow(2,15)~pow(2,15 ...

  6. Android数据库代码优化(1) - 从Google的数据库guide说起

    假如我们没有任何在Android上使用SQLite的经验,现在要开始在工作中用SQLite存储一些数据.OK, 我们去看google的官方培训文档吧,http://developer.android. ...

  7. html中<video>显示视频的时候,MP4的格式问题

    html支持的视频格式:HTML5视频 注意 浏览器对mp4 的编码方式要求的非常严格 视频编码必须是H.264 音频编码必须是: AAC

  8. c++使用http协议上传文件到七牛云服务器

    使用c++ http协议上传文件到七牛服务器时,比较搞的一点就是header的设置: "Content-Type:multipart/form-data;boundary=xxx" ...

  9. Bootstrap和IE何时能相亲相爱啊~

    公司新项目,嘚瑟了一下,用了用Bootstrap... ... 发现了一个小坑(也许只是对我而言)... ... 使用了2.x的Jquery,在chrome等高版本浏览器一切顺利... ... 然,3 ...

  10. HDU - 6433: H. Pow (简答题,输出大数)

    There are n numbers 3^0, 3^1, . . . , 3^n-1. Each time you can choose a subset of them (may be empty ...