< Summary

Information
Class: LeetCode.Algorithms.StoneGame.StoneGameDynamicProgramming
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\StoneGame\StoneGameDynamicProgramming.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 44
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
StoneGame(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\StoneGame\StoneGameDynamicProgramming.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.StoneGame;
 13
 14/// <inheritdoc />
 15public class StoneGameDynamicProgramming : IStoneGame
 16{
 17    /// <summary>
 18    ///     Time complexity - O(piles.Length^2)
 19    ///     Space complexity - O(piles.Length^2)
 20    /// </summary>
 21    /// <param name="piles"></param>
 22    /// <returns></returns>
 23    public bool StoneGame(int[] piles)
 224    {
 225        var dp = new int[piles.Length, piles.Length];
 26
 2027        for (var i = 0; i < piles.Length; i++)
 828        {
 829            dp[i, i] = piles[i];
 830        }
 31
 1632        for (var length = 2; length <= piles.Length; length++)
 633        {
 3634            for (var i = 0; i <= piles.Length - length; i++)
 1235            {
 1236                var j = i + length - 1;
 37
 1238                dp[i, j] = Math.Max(piles[i] - dp[i + 1, j], piles[j] - dp[i, j - 1]);
 1239            }
 640        }
 41
 242        return dp[0, piles.Length - 1] > 0;
 243    }
 44}

Methods/Properties

StoneGame(System.Int32[])