LeetCode||3. Longest Substring Without Repeating Characters
来源:互联网 发布:实体店结算软件 编辑:程序博客网 时间:2024/06/06 04:07
3. Longest Substring Without Repeating Characters
- Total Accepted: 200515
- Total Submissions: 860059
- Difficulty: Medium
- Contributors: Admin
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb"
, the answer is "abc"
, which the length is 3.
Given "bbbbb"
, the answer is "b"
, with the length of 1.
Given "pwwkew"
, the answer is "wke"
, with the length of 3. Note that the answer must be asubstring, "pwke"
is a subsequence and not a substring.
代码如下:
public class Solution { public int lengthOfLongestSubstring(String s) { int length = s.length(); if (length == 0) { return 0; } int [] countTable = new int[256]; for(int i = 0;i<256;i++){ countTable[i] = -1; } int max = 1; int start = 0; int end = 1; countTable[s.charAt(0)] = 0; while (end < length) { //Has not reached a duplicate char if (countTable[s.charAt(end)] >= start) { start = countTable[s.charAt(end)] + 1; } max = Math.max(max, end - start + 1); countTable[s.charAt(end)] = end; end++; } return max; }}
0 0
- [LeetCode]3.Longest Substring Without Repeating Characters
- LeetCode 3.Longest Substring Without Repeating Characters
- LeetCode --- 3. Longest Substring Without Repeating Characters
- [Leetcode] 3. Longest Substring Without Repeating Characters
- [leetcode] 3.Longest Substring Without Repeating Characters
- [leetcode] 3. Longest Substring Without Repeating Characters
- [Leetcode]3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- 【Leetcode】3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- LeetCode-3.Longest Substring Without Repeating Characters
- LeetCode 3.Longest Substring Without Repeating Characters
- LeetCode - 3.Longest Substring Without Repeating Characters
- Leetcode 3. Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters LeetCode
- (Leetcode)3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- LeetCode-3. Longest Substring Without Repeating Characters
- 嵌套查询
- mysql初识之数据文件及其他文件
- 清泽心雨 移动互联组 2016 机试题解
- Linux内核Timer使用注意事项
- 用位运算生成下一个含有k个1的二进制数
- LeetCode||3. Longest Substring Without Repeating Characters
- 计算三角形的面积
- hdu 3254 Corn Fields
- 关于uboot Makefile的总体理解(x210开发板Makefile为例)
- 【Hadoop入门学习系列之一】Ubuntu下安装Hadoop(完全分布模式)
- Measurement Studio for C#简介
- 二叉树的递归和非递归方式的三种遍历
- Java类的初始化问题
- 如何选择开源许可证