leetcode
来源:互联网 发布:爱淘宝下载 编辑:程序博客网 时间:2024/05/14 17:29
Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
For example,
S = "ADOBECODEBANC"
T = "ABC"
Minimum window is "BANC"
.
Note:
If there is no such window in S that covers all characters in T, return the empty string “”.
If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in S.
Solution:
public String minWindow(String s, String t) { int[] map = new int[128]; for (char c : t.toCharArray()) { map[c]++; } int begin = 0; int end = 0; int counter = t.length(); int len = Integer.MAX_VALUE; int head = 0; while (end < s.length()) { if (map[s.charAt(end++)]-- > 0) counter--; while (counter == 0) { if (end - begin < len) len = end - (head = begin); if (map[s.charAt(begin++)]++ == 0) counter++; } } return len == Integer.MAX_VALUE ? "" : s.substring(head, head + len); }
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- AbsListView.obtainView(AbsListView.java:2353)
- 关于Git提交代码
- vs目录(继承的值)配置
- python知识点:浅拷贝和深拷贝
- 【图像处理】FLIR Tags
- leetcode
- MTK sensor 框架
- java-List去重得到的经验
- 软件测试使用到的网站
- 为tomcat制作sha-256自签名证书
- Ubiquitous Religions POJ
- 简单实现android炫酷注册页面动画
- Linux GPIO驱动
- (转)FFmpeg 基本用法