Validate a Simplified Mahjong Winning Hand
Problem statement
tiles contains exactly fourteen tile ranks from 1 through 9. A winning hand can be partitioned into exactly four melds and one pair.
- A pair is two equal ranks.
- A meld is either three equal ranks or three consecutive ranks.
Every tile occurrence must be used exactly once. Return whether the hand is winning. Special Mahjong hands are not included.
Function
isWinningMahjongHand(tiles: int[]) → booleanExamples
Example 1
tiles = [1,1,1,2,3,4,2,3,4,7,8,9,5,5]return = trueUse triple 111, runs 234, 234, and 789, plus pair 55.
Example 2
tiles = [1,1,2,2,3,3,4,4,5,5,6,6,7,7]return = trueUse pair 11 and runs 234, 234, 567, and 567.
Example 3
tiles = [1,1,1,2,2,2,3,3,3,4,4,5,6,9]return = falseNo choice of pair lets all remaining tiles form four complete melds.
Constraints
tiles.length == 14.1 <= tiles[i] <= 9.- No rank appears more than four times.