Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
努力调试leetcode算法的java解决方案_Java_Algorithm_Debugging - Fatal编程技术网

努力调试leetcode算法的java解决方案

努力调试leetcode算法的java解决方案,java,algorithm,debugging,Java,Algorithm,Debugging,我试图在这里解决这个问题: 我的代码提供了错误的答案,但我不明白为什么。当我看着它,在脑海中反复思考时,我不知道它到底出了什么问题 以下是我的解决方案: (如果可能的话,请不要向我提供关于更有效方法的信息,我想自己尝试解决这个问题) 公共类解决方案{ 公共内部陷阱(内部[]高度){ int TotalWaterCapture=0; 对于(int i=0;i=0;x--){ if(高度[x]>tallestLeftwardHeight){ 最左边的高度=x; } } int tallestRigh

我试图在这里解决这个问题:

我的代码提供了错误的答案,但我不明白为什么。当我看着它,在脑海中反复思考时,我不知道它到底出了什么问题

以下是我的解决方案: (如果可能的话,请不要向我提供关于更有效方法的信息,我想自己尝试解决这个问题)

公共类解决方案{
公共内部陷阱(内部[]高度){
int TotalWaterCapture=0;
对于(int i=0;i=0;x--){
if(高度[x]>tallestLeftwardHeight){
最左边的高度=x;
}
}
int tallestRightwardHeight=高度[i];
对于(int y=i;ytallestRightwardHeight){
tallestRightwardHeight=y;
}
}
总截流高度+=(数学最小值(最高左向高度,最高右向高度)-高度[i];
}
}
返回被困的水;
}
}
谢谢你的帮助

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

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

应该是

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

在这里添加问题陈述,而不是它的链接
                if (height[y] > tallestRightwardHeight){
                    tallestRightwardHeight = y;
                }
                if (height[y] > tallestRightwardHeight){
                    tallestRightwardHeight = height[y];
                }