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. redis memcache rabbitMQ

    Python之路[第九篇]:Python操作 RabbitMQ.Redis.Memcache.SQLAlchemy Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动 ...

  2. TCPL学习毕节:第六章hash表

    对于P126的哈希表构成: struct nlist *install(char *name, char *defn) { struct nlist *np; unsigned hashval; if ...

  3. UIPickerView/UIDatePicker/程序启动的完整过程

    一.UIPickerView 1.UIPickerView的常见属性 数据源(用来告诉UIPickerView有多少列多少行) @property(nonatomic,assign) id<UI ...

  4. DRF 用户频率限制

    DRF 用户频率限制 为什么要限流 1 防爬虫 匿名用户 无法限制,代理 已登录,用户名限制:买代理 2 提供服务(接口--不同用户的访问次数不一样) vip 限制访问次数 BaseThrottle ...

  5. List列表按照对象进行排序

    在某些业务场景下需要根据list列表中对象的字段进行排序.今天就以实例说明: 实体类 public class Product { private int discount; // 省略getter/ ...

  6. windows ubuntu Android studio安装好启动没反应解决方法

     参考:http://blog.csdn.net/qq305013720/article/details/8934152 目前有三种解决方案,都是针对执行studio.bat出现错误导致andro ...

  7. How do I create zip file in Servlet for download?

    原文链接:https://kodejava.org/how-do-i-create-zip-file-in-servlet-for-download/ The example below is a s ...

  8. hexo多主题切换

    今天看到一个朋友在github上面的issue 大概问题就是怎么在不同的电脑上面使用 git有个这么个东西Submoudle中文叫做子模块 具体使用教程看这里Git-工具-子模块 这里只说怎么搞hex ...

  9. [分享]Google 全球 IP 地址库[Google Global Cache IPs]

    Google 全球 IP 地址库 IP 地址来源:http://www.kookle.co.nr,共计4351个. Bulgaria 93.123.23.1 93.123.23.2 93.123.23 ...

  10. GIL、死锁与递归锁

    一.互斥锁 用互斥锁,目的:局部串行(保护自己的数据 进程之间数据不共享,但是共享同一套文件系统,所以访问同一个文件,或同一个打印终端,是没有问题的,竞争带来的结果就是错乱,如何控制,就是加锁处理(即 ...