Thursday, February 5, 2015

LeetCode [135] Candy



Note:
  • step 1: give each child one candy regardless of his/her rating
  • step 2: forward, if i-th child has higher rating than (i-1)-th child, candies[i] should be greater than candies[i-1]
  • step 3: backward, if i-th child has higher rating than (i+1)-th child, candies[i] should be greater candies[i+1]
  • return sum of candies
Ref

No comments:

Post a Comment