Leetcode Note: Go - Keep Multiplying Found Values by Two

Keep Multiplying Found Values by Two - LeetCode
https://leetcode.com/problems/keep-multiplying-found-values-by-two/

  • Go 言語で取り組んだメモ

回答

Go for loop solution - Keep Multiplying Found Values by Two - LeetCode
https://leetcode.com/problems/keep-multiplying-found-values-by-two/solutions/2481657/go-for-loop-solution/

func findFinalValue(nums []int, original int) int {
    var numSet [1001]int
    
    for _, num := range nums {
        numSet[num]++
    }
    
    for {
        if original > 1001 || numSet[original] == 0 {
            break
        }
        
        numSet[original] = original*2
        original = original*2
    }
    
    return original
}