Skip to content

Latest commit

 

History

History
109 lines (90 loc) · 2.26 KB

_877. Stone Game.md

File metadata and controls

109 lines (90 loc) · 2.26 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 11, 2024

Last updated : July 11, 2024


Related Topics : Array, Math, Dynamic Programming, Game Theory

Acceptance Rate : 71.43 %


Solutions

Python

class Solution:
    def stoneGame(self, piles: List[int]) -> bool:
        pilesDq = deque(piles)
        alice, bob = 0, 0
        who = True
        while pilesDq :
            maxx = 0
            if pilesDq[0] > pilesDq[-1] :
                maxx = pilesDq.popleft()
            else :
                maxx = pilesDq.pop()

            if who :
                alice += maxx
            else :
                bob += maxx

        return alice > bob
class Solution:
    def stoneGame(self, piles: List[int]) -> bool:
        return True

C

bool stoneGame(int* piles, int pilesSize) {
    return true;
}

C++

class Solution {
public:
    bool stoneGame(vector<int>& piles) {
        return true;
    }
};

Go

func stoneGame(piles []int) bool {
    return true;
}

Java

class Solution {
    public boolean stoneGame(int[] piles) {
        return true;
    }
}

JavaScript

/**
 * @param {number[]} piles
 * @return {boolean}
 */
var stoneGame = function(piles) {
    return true;
};