Created
March 4, 2015 10:12
-
-
Save ninjachen/850a6248f3d6a1bc09fd to your computer and use it in GitHub Desktop.
candy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.npi.blureffect; | |
/** | |
* Created by ninja on 3/4/15. | |
*/ | |
public class NinjaCandy { | |
public int candy(int[] ratings) { | |
if (ratings == null || ratings.length < 0) | |
return -1; | |
int[] candys = new int[ratings.length]; | |
//遍歷,取出分數從小到大的childrenseq | |
int[] rating_seq = bublesort(ratings); | |
int max_candy = 1; | |
for (int i = 0; i < rating_seq.length; i++) { | |
int current_seq = rating_seq[i]; | |
candys[current_seq] = max_candy++; | |
} | |
//calculate total_candy_num | |
int total_candy_num = 0; | |
for (int i = 0; i < candys.length; i++) { | |
total_candy_num += candys[i]; | |
} | |
return total_candy_num; | |
} | |
int[] bublesort(int[] ratings) { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not finish yet