LeetCode3. 无重复字符的最长子串(Java)
2019-03-18 15:05
771 查看
题目:
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
示例:
代码:
- 解法
class Solution { public int lengthOfLongestSubstring(String s) { int n = s.length(), ans = 0; int[] index = new int[128]; // current index of character // try to extend the range [i, j] for (int j = 0, i = 0; j < n; j++) { i = Math.max(index[s.charAt(j)], i); ans = Math.max(ans, j - i + 1); index[s.charAt(j)] = j + 1; } return ans; } }
- 别人的代码
class Solution { public int lengthOfLongestSubstring(String s) { int n = s.length(), ans = 0; int[] index = new int[128]; // current index of character // try to extend the range [i, j] for (int j = 0, i = 0; j < n; j++) { i = Math.max(index[s.charAt(j)], i); ans = Math.max(ans, j - i + 1); index[s.charAt(j)] = j + 1; } return ans; } }
相关文章推荐
- leetcode 3. 无重复字符的最长子串(Java 版)
- LeetCode3. 无重复字符的最长子串(python)
- [Leetcode] 3.无重复字符的最长子串
- 【Leetcode一刷】3.无重复字符的最长子串
- LeetCode题解(python)-3.无重复字符的最长子串
- leetcode 3. 无重复字符的最长子串
- LeetCode3. python实现:无重复字符的最长子串问题☆☆
- 【LeetCode】3. 无重复字符的最长子串(Longest Substring Without Repeating Characters,24.2%,中等)
- LeetCode题目C++实现:3. 无重复字符的最长子串
- leetcode 3.无重复字符的最长子串
- LeetCode 3. 无重复字符的最长子串
- LeetCode 3. 无重复字符的最长子串
- 【LeetCode】3.无重复字符的最长子串 结题报告 (C++)
- Leetcode 3. 无重复字符的最长子串
- Leetcode刷题35-3.无重复字符的最长子串(C++)
- LeetCode 3. 无重复字符的最长子串 Python
- leetcode:Longest Substring Without Repeating Characters (寻找最长无重复字符的子串)
- LeetCode - 无重复字符的最长子串
- C#leetcode刷题3无重复字符的最长子串
- [leetcode]Longest Substring Without Repeating Characters【最长不重复字符子串】