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. java10---点餐系统

    public class OrderMsg { public static void main(String[] args) throws Exception { /** * 订餐人姓名.选择菜品.送 ...

  2. LeetCode OJ:Spiral Matrix(螺旋矩阵)

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  3. angularJs 模拟jQuery中的this

    在angularJs中,this指向$scope!可以$event配合使用$(event.target)实现,代码如下: HTML部分: <p ng-click="testClick( ...

  4. libwebsockets libwebsockets-webserver.c hacking

    /********************************************************************************** * libwebsockets ...

  5. Python之xpath

    xpath是一种在XML文档中定位元素的语言,常用于xml.html文件解析,比css选择器使用方便XML文件最小构成单元: - element(元素节点) - attribute(属性节点) - t ...

  6. python3 chromeDriver 安装与配置

    1. 准备工作 在这之前请确保已经正确安装好了Chrome浏览器并可以正常运行,安装过程不再赘述. 2. 查看版本 点击Chrome菜单"帮助"→"关于Google Ch ...

  7. NSNotificationCenter 通知中心传值

    1.NSNotification 这个类可以理解为一个消息对象,其中有三个成员变量. 这个成员变量是这个消息对象的唯一标识,用于辨别消息对象. @property (readonly, copy) N ...

  8. js 预解析

    前言 JavaScript是解释型语言是毋庸置疑的,但它是不是仅在运行时自上往下一句一句地解析的呢? 事实上或某种现象证明并不是这样的,通过<JavaScript权威指南>及网上相关资料了 ...

  9. flask的request的用法

    其中在头部取值是这样的,request.headers,得到的是一个字典 参考链接:http://blog.csdn.net/yannanxiu/article/details/53116652

  10. JAMstack 技术要点

    1.  简要说明 Modern web development architecture based on client-side JavaScript, reusable APIs,and preb ...