Skip to content

Instantly share code, notes, and snippets.

@ninjachen
Created March 4, 2015 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninjachen/850a6248f3d6a1bc09fd to your computer and use it in GitHub Desktop.
Save ninjachen/850a6248f3d6a1bc09fd to your computer and use it in GitHub Desktop.
candy
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;
}
}
@ninjachen
Copy link
Author

not finish yet

@ninjachen
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment