[Python/GO] 🌟 Greedy Counter Solution and Explanation 💕
\uD83D\uDC46Please UPVOTE it if you find my soulutions are useful \uD83D\uDC46 Feel free to ask any question\n# [Python/GO] \uD83C\uDF1F Greedy Counter Solution
**\uD83D\uDC46Please UPVOTE it if you find my soulutions are useful \uD83D\uDC46 Feel free to ask any question**\n# [Python/GO] \uD83C\uDF1F Greedy Counter Solution and Explanation \uD83D\uDC95\n## 1\uFE0F\u20E3 Main Idea:\n1. A very greedy idea is to check if we can swap dice\'s number to make them equals to 1~6. But actually, we only have to deal with two number **tops[0] and bottoms[0]**\n\t* Because at maximum we only have to deal with two possible number swap, all remaining number will be invalid since we can\'t swap other dices to have same value besides these two number.\n2. We simply loops through both tops and bottoms with two counter **swapTopCnt** and **swapBottomCnt** to store either we swap current value from top to bottom or otherwise.\n\n## Complexity Analysis\n* Time: O(N): Let N be number of element in tops\' length\n* Space: O(1)\n\n## Code\n\n**Python**\n```python\nclass Solution:\n    def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:\n        res = float(\'inf\')\n        # Loops through tops[0] or bottoms[0]\n        for i in (tops[0], bottoms[0]):\n            isValid = True\n            swapTopCnt, swapBottomCnt = 0, 0\n            for top, bottom in zip(tops, bottoms):\n                if top == i and bottom == i:\n                    continue\n                # Count if we have to  Swap Top to Bottom\n                elif top == i:\n                    swapTopCnt += 1\n                # Count if we have to  Swap Bottom to Top\n                elif bottom == i:\n                    swapBottomCnt += 1\n                # If not valid, don\'t update res\n                else:\n                    isValid = False\n                    break\n            # Check whether make all top value equal, or bottom value equal takes minimum swaps\n            if isValid:\n                res = min(res, swapTopCnt, swapBottomCnt)\n                \n        return res if res != float(\'inf\') else -1\n```\n**Go** : Hope find a elegant better way to write if isValid part\n```go\nfunc minDominoRotations(tops []int, bottoms []int) int {\n    res := -1\n    // Loops through tops[0] or bottoms[0]\n    for _, val := range([]int{tops[0], bottoms[0]}){\n        isValid := true\n        swapTopCnt, swapBottomCnt := 0, 0\n        for idx:= 0; idx < len(tops); idx++{\n            if tops[idx] == val && bottoms[idx] == val{\n                continue\n            // Count if we have to  Swap Top to Bottom\n            } else if tops[idx] == val {\n                swapTopCnt += 1\n            // Count if we have to  Swap Bottom to Top\n            } else if bottoms[idx] == val{\n                swapBottomCnt += 1\n            // If not valid, don\'t update res\n            } else{\n                isValid = false\n                break\n            }\n        }\n        // Check whether make all top value equal, or bottom value equal takes minimum swaps\n        if isValid{\n            if res == -1{\n                res = swapTopCnt\n            }\n            if swapTopCnt < res{\n                res = swapTopCnt\n            }\n            if swapBottomCnt < res{\n                res = swapBottomCnt\n            }\n        }\n    }\n    \n    return res\n}\n```\n\n* See more 2022 Daily Challenge Solution : [GitHub](https://github.com/gcobs0834/2022-Daily-LeetCoding-Challenge-python3-)
[]