mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 09:16:32 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			14 lines
		
	
	
		
			250 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			14 lines
		
	
	
		
			250 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package main
 | 
						|
 | 
						|
func distributeCandies(n int, limit int) int64 {
 | 
						|
	var res int64 = 0
 | 
						|
	for i := 0; i <= min(n, limit); i++ {
 | 
						|
		last := n - i
 | 
						|
		if last > 2*limit {
 | 
						|
			continue
 | 
						|
		}
 | 
						|
		res += int64(min(last, limit) - max(0, last-limit) + 1)
 | 
						|
	}
 | 
						|
	return res
 | 
						|
}
 |