Leetcode Note: Go - Water Bottles

Water Bottles - LeetCode
https://leetcode.com/problems/water-bottles/

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

回答

Go Solution - 0ms 1.9mb - Water Bottles - LeetCode
https://leetcode.com/problems/water-bottles/solutions/840022/go-solution-0ms-1-9mb/

func numWaterBottles(numBottles int, numExchange int) int {
	total := numBottles
	empties := numBottles
	for empties >= numExchange {
		exchanged := empties / numExchange
		total += exchanged
		empties = exchanged + empties%numExchange

	}

	return total
}