Q:

Struggling to debug java solution to leetcode algorithm

I was trying to solve this problem here: https://leetcode.com/problems/trapping-rain-water/#/description
And my code is providing incorrect answers, but I can't understand why. When I look at it and I run it through my head, I can't figure out what's wrong with it.
Here is my solution:
(Please don't provide me with information about a more efficient methodology if possible, I want to try and figure that out on my own).
public class Solution {
    public int trap(int[] height) {
        int totalWaterTrapped = 0;
        for (int i = 0; i < height.length; i++){
            if (i == 0){
                continue;
            } else if (i == (height.length - 1)){
                continue;
            } else {
                int tallestLeftwardHeight = height[i];
                for (int x = i; x >= 0; x--){
                    if (height[x] > tallestLeftwardHeight){
                        tallestLeftwardHeight = x;
                    }
                }
                int tallestRightwardHeight = height[i];
                for (int y = i; y < height.length; y++){
                    if (height[y] > tallestRightwardHeight){
                        tallestRightwardHeight = y;
                    }
                }

                totalWaterTrapped += (Math.min(tallestLeftwardHeight, tallestRightwardHeight) - height[i]);
            }
        }
        return totalWaterTrapped;
    }
}

Thank you kindly for any help.

A:

                if (height[x] > tallestLeftwardHeight){
                    tallestLeftwardHeight = x;
                }

should be 
                if (height[x] > tallestLeftwardHeight){
                    tallestLeftwardHeight = height[x];
                }

and
                if (height[y] > tallestRightwardHeight){
                    tallestRightwardHeight = y;
                }

should be
                if (height[y] > tallestRightwardHeight){
                    tallestRightwardHeight = height[y];
                }

