简单模拟一下,本来想数学的,但数学全还回去了) 1impl Solution {2 pub fn distribute_candies(candies: i32, num_people: i32) -> Vec<i32> {3 let num_people = num_people as usize;4 let mut candies = candies;5 let mut vec = vec![0; num_people as usize];6 7 let mut index = 0;8 let mut now = 1;9 while candies >= now {10 vec[index] += now;11 candies -= now;12 now += 1;13 index = (index + 1) % (num_people as usize);14 }15 vec[index] += candies;16 17 vec18 }19}