LeetCode Longest Substring Without Repeating Characters
来源:互联网 发布:windows bat脚本 示例 编辑:程序博客网 时间:2024/05/17 07:47
链接: https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/
字符串中最长连续不重复子序列,用JAVA中的哈希表比较方便
public class Solution { public int lengthOfLongestSubstring(String s) {int n=s.length();int end=0;int start=0;int ans=0;HashMap<Character,Integer> map=new HashMap<Character,Integer>();while(end<n){char c=s.charAt(end);Integer index=map.get(c);if(index!=null&&index>=start)//发现重复元素{ans=Math.max(ans,end-start);start=index+1;}else{map.put(c, end);end++;}}if(end-start>ans) ans=end-start;return ans; }}
0 0
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- leetcode之Longest Substring Without Repeating Characters
- IOS学习之Quartz2D
- 页面右下角弹广告案例
- 小议TCP带外数据(OOB--out of band)
- 【屌丝程序的口才逆袭演讲稿50篇】第六篇:两个年轻人挣钱的故事 【张振华.Jack】
- C# Socket编程(2)识别网络主机
- LeetCode Longest Substring Without Repeating Characters
- Hardcoded string "Button", should use @string resourc
- malware analysis
- 编写程序利用模板交换不同类型的两个数
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter(经典的DP)
- 前端页面实现滚动加载数据的案例
- 数据库篇之[bsp_adverts]数据表-网上商城BrnShop1.9升级至2.1升级说明(非官方版本)
- ORACLE触发器详解
- 各个uboot版本下载地址