昨天刷题,不经意间刷出来一个小彩蛋👇
今天醒来便发现, 卧槽,自己出现在解答列表第二,这lima,我一个小辣鸡也上榜了?🐂
话不多说,看键
警告,长文劝退,不是我啰嗦,是这题目一直在bibi赖赖
Simple Fun #345: The Original Numbers
Task
Some players are playing a game: They stand in a circle, and each player has a card with the number on it. They put the card in front of their chest. That is to say, each player can see the numbers of other players, but can’t see his own.
In each turn, each player adds up the numbers he sees and writes it to the new card. For example:
There are 3 players: A,B and C
The original numbers of A,B,C is 1,0,4
Let’s see the next 4 turns:
Player: A B C
turn 0: 1 0 4
turn 1: 4 5 1 // A:0+4;B:1+4;C:1+0
turn 2: 6 5 9 // A:5+1;B:4+1;C:4+5
turn 3: 14 15 11 // A:5+9;B:6+9;C:6+5
turn 4: 26 25 29 // A:15+11;B:14+11;C:14+15
Hmm… Your task is coming: Now, suppose you don’t know the original numbers. You are given the final numbers(an array) and turns(a positive integer), can you get the original numbers?
Examples
For finalNumbers = [26,25,29] and turns = 4. The output should be [1,0,4].
The val