public int candy(int[] ratings) {
		// handle the null case
		if (ratings == null)
			return 0;
		int size = ratings.length;
		// return if size is 0 or 1
		if (size < 1)
			return 0;
		if (size == 1)
			return 1;
		int[] candys = new int[size];
		int i;
		// initialize the candy array, allocate 1 candy for each child
		for (i = 0; i < size; i++) {
			candys[i] = 1;
		}
		// check from left to right
		for (i = 1; i < size; i++) {
			if (ratings[i - 1] < ratings[i])
				candys[i] = candys[i - 1] + 1;
		}
		// check from right to left
		for (i = size - 2; i >= 0; i--) {
			if (ratings[i + 1] < ratings[i] && candys[i + 1] >= candys[i])
				candys[i] = candys[i + 1] + 1;
		}
		return sumOfArray(candys);
	}