MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / getWinner

Function getWinner

valid_tic_tac_toe_state_794/solution.go:49–84  ·  view source on GitHub ↗
(board []string)

Source from the content-addressed store, hash-verified

47}
48
49func getWinner(board []string) []string {
50 b := strings.Join(board, "")
51 win := [][]int{
52 {0, 1, 2},
53 {3, 4, 5},
54 {6, 7, 8},
55 {0, 3, 6},
56 {1, 4, 7},
57 {2, 5, 8},
58 {0, 4, 8},
59 {2, 4, 6},
60 }
61
62 winners := make([]string, 0)
63 for _, w := range win {
64 x := 0
65 o := 0
66 for _, s := range w {
67 if string(b[s]) == "X" {
68 x++
69 } else if string(b[s]) == "O" {
70 o++
71 }
72 }
73
74 if x == 3 {
75 winners = append(winners, "X")
76 }
77
78 if o == 3 {
79 winners = append(winners, "O")
80 }
81 }
82
83 return winners
84}

Callers 1

validTicTacToeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected