public static int candy(int[] ratings) {
        if (ratings == null && ratings.length == 0) {
            return 0;
        }
        if (ratings.length == 1) {
            return 1;
        }
        int[] tables = new int[ratings.length];
        tables[0] = 1;
        for (int i = 1; i < ratings.length; i++) {
            if (ratings[i] > ratings[i - 1]) {
                tables[i] = tables[i - 1] + 1;
            } else {
                tables[i] = 1;
            }
        }

        for (int i = ratings.length - 2; i >= 0; i--) {
            if (ratings[i] > ratings[i + 1] ) {
                if( tables[i] < tables[i + 1] + 1) {
                    tables[i] = tables[i + 1] + 1;
                }
            }
        }
        int sum = 0;
        for(int a : tables){
            sum += a;
        }
        return sum;
    }