Minimum Window Substring
来源:互联网 发布:mysql truncate速度 编辑:程序博客网 时间:2024/06/14 01:47
public class Solution { public String minWindow(String s, String t) { if (s == null || s.length() == 0) { return ""; } Map<Character, Integer> map = new HashMap<>(); for (int i = 0; i < t.length(); i++) { char c = t.charAt(i); if (map.containsKey(c)) { map.put(c, map.get(c) + 1); } else { map.put(c, 1); } } int prev = 0, count = 0, minLen = s.length() + 1; String res = ""; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (map.containsKey(c)) { map.put(c, map.get(c) - 1); if (map.get(c) >= 0) { count++; } while (count == t.length()) { char p = s.charAt(prev); if (map.containsKey(p)) { map.put(p, map.get(p) + 1); if (map.get(p) > 0) { count--; int len = i - prev + 1; if (len < minLen) { minLen = len; res = s.substring(prev, i + 1); } } } prev++; } } } return res; }}
0 0
- LeetCode: Minimum Window Substring
- LeetCode Minimum Window Substring
- LeetCode : Minimum Window Substring
- [LeetCode] Minimum Window Substring
- [Leetcode] Minimum Window Substring
- Minimum Window Substring
- LeetCode: Minimum Window Substring
- Minimum Window Substring
- [LeetCode]Minimum Window Substring
- Minimum Window Substring
- Minimum Window Substring
- [leetcode]Minimum Window Substring
- Minimum Window Substring
- Leetcode:Minimum Window Substring
- LeetCode-Minimum Window Substring
- [leetcode] Minimum Window Substring
- [leetcode] Minimum Window Substring
- leetcode Minimum Window Substring
- Merge Intervals
- Android Studio 真正国内SDK在线更新说明
- Remove Invalid Parentheses
- 读《张爱玲:她从海上来》有感
- Reverse Linked List
- Minimum Window Substring
- 【9409】集合的划分问题
- [初学Unity]Graphics-02.Rendering and Shading
- 雾雨魔理沙
- JavaScript查找奇偶异常值
- 提示框
- Hibernate常用工具类
- java编程自学记录(day01)
- 神器nmap的web版-Rainmap Lite