class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap windows = new HashMap();
int left = 0;
int right = 0;
int res = 0;
while(right < s.length()) {
Character c = s.charAt(right);
right++;
windows.put(c, windows.getOrDefault(c, 0) + 1);
while(windows.get(c).compareTo(1) > 0 ){
Character d = s.charAt(left);
left++;
windows.remove(d);
}
res = Math.max(res, right - left);
}
return res;
}
}
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode p1 = l1;
ListNode p2 = l2;
ListNode dummy = new ListNode(-1);
ListNode p = dummy;
int carry = 0;
while(p1 != null || p2 != null || carry > 0){
int val = carry;
if(p1 != null){
val += p1.val;
p1 = p1.next;
}
if(p2 != null){
val += p2.val;
p2 = p2.next;
}
carry = val/10;
val = val % 10;
p.next = new ListNode(val);
p = p.next;
}
return dummy.next;
}
}
class Solution {
public int maxArea(int[] height) {
// 总体算法往中间缩,面积有收缩的趋势
// 面积(求最大) = 长(逐渐收缩) * 宽
// 等出结论: 宽势必要逐渐变长才符合题意
int left = 0, right = height.length - 1;
int res = 0;
while (left < right) {
// 记录当前容量,有可能最大
int cur_area = Math.min(height[left], height[right]) * (right - left);
res = Math.max(res, cur_area);
// 但向两边缩的时候,需要遵循高度边长的规则
// 那边高我就要那个
if (height[left] < height[right]) {
// 右边高,保留右边,舍弃左边,左边右移换新的
left++;
} else {
// 左边高,保留左边,舍弃有边
right--;
}
}
return res;
}
}



