对撞型 Palindrome
Trapping Rain Water
public int trap(int[] height) {
int n = height.length;
int left = 0, right = n - 1;
int water = 0;
int leftMax = 0, rightMax = 0;
while (left < right) {
leftMax = Math.max(leftMax, height[left]);
rightMax = Math.max(rightMax, height[right]);
if (leftMax < rightMax) {
water += leftMax - height[left];
left++;
} else {
water += rightMax - height[right];
right--;
}
}
return water;
}Longest Palindromic Substring
Reverse words in a String II
Next Permutation
Next Greater Element III
Valid Palindrome II
Last updated