题目描述

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1.

解析:题目的意思是求最大不重复的连续的子串,注意字符不能再前面重复。

public class Solution {public int lengthOfLongestSubstring(String s) {int max=0;for(int i=0;i<s.length();i++){int count=1;//当前字符计数1次for(int j=i+1;j<s.length();j++){int start=i;boolean flag=false;while (start<j){if(s.charAt(j)==s.charAt(start)){flag=true;break;}start++;}if(!flag){//在之前的字符串里没有出现过count++;}else {//出现后就没必要继续了break;}}if(count>=max){max=count;}}return max;}
}

《leetcode》longest-substring-without-repeating相关推荐

  1. 【贪心】LeetCode 3. Longest Substring Without Repeating Characters

    LeetCode 3. Longest Substring Without Repeating Characters Solution1:我的答案 该方法中哈希表记录的是字符出现的次数.标准的贪心算法 ...

  2. [LeetCode]3.Longest Substring Without Repeating Characters

    [题目] Given a string, find the length of the longest substring without repeating characters. For exam ...

  3. LeetCode:3. Longest Substring Without Repeating Characters

    https://leetcode.com/problems/longest-substring-without-repeating-characters/description/ 内容描述: Give ...

  4. LeetCode 3. Longest Substring Without Repeating Characters-- c++,java,python解法

    题目地址: Given a string, find the length of the longest substring without repeating characters. Example ...

  5. [LeetCode]--3. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  6. leetcode 3. Longest Substring Without Repeating Characters 最长非重复子串的长度 滑动窗口法

    题目链接 根据我们之前介绍的滑动窗口法的解法: 滑动窗口法详解 leetcode 438. Find All Anagrams in a String 滑动窗口法 这题,我们不难解决,使用之前的模板. ...

  7. python刷leetcode_零基础python刷leetcode -- 3. Longest Substring Without Repeating Characters

    算法很重要,但是每天也需要学学python,于是就想用python刷leetcode 的算法题,和我一起开始零基础python刷leetcode之旅吧.如有不对的地方,希望指正,万分感谢~~ 题目 最 ...

  8. leetcode 3. Longest Substring Without Repeating Characters | 3. 无重复字符的最长子串(双指针+滑窗)

    题目 https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题解 双指针+滑窗,维护一个 set, ...

  9. LeetCode 3 Longest Substring Without Repeating Characters 区间,想法 难度:1

    https://leetcode.com/problems/longest-substring-without-repeating-characters/ 思路:从某点结束所能取到的最早开头是到目前出 ...

  10. leetcode 3. Longest Substring Without Repeating Characters

    记得这要+1,j = std::max(j,container[s[i]]+1); class Solution { public:int lengthOfLongestSubstring(strin ...

最新文章

  1. 动漫风格迁移 AnimeGANv2 ,发布线上运行 Demo
  2. tensorflow gan 网络 示例
  3. centos 7 yum 安装 MongoDB 4.2
  4. ctpn论文阅读与代码
  5. [进阶] --- Python3 异步编程详解(史上最全篇)
  6. 云图说丨手把手教你为容器应用配置弹性伸缩策略
  7. SpringBoot指南(二)——常用注解及操作
  8. Keras 构建DNN 对用户名检测判断是否为非法用户名(从数据预处理到模型在线预测)...
  9. DownList下的部门树
  10. html5 datepicker ios,iOS DatePicker日期时间选择器【组件】
  11. java技术学习路线
  12. 详尽Ubuntu18安装搜狗输入法教程
  13. HTML5七夕情人节表白网页制作【蓝色3D动态相册】HTML+CSS+JavaScript 程序员表白3D相册代码 html生日快乐祝福网页制作
  14. android开发--不安装支付宝客户端调H5页面问题
  15. java vo层_JAVA3个数据层(pojo,dto,vo)、dao层、services层、controller层解释
  16. canvas mdn_MDN文档 canvas教程笔记
  17. 自定义View之仿QQ运动步数进度效果
  18. matlab摩托车刹车问题,安全骑行篇,摩托车刹车的基本知识与技巧!
  19. SQLStudio下载
  20. videojs实现视频打点标记 Vue

热门文章

  1. JUC锁-Semaphore(八)
  2. leetcode--116. 填充每个节点的下一个右侧节点指针
  3. idea点击表单按钮不做post反应
  4. 21行代码AC——HDU1106 排序
  5. Apache网页优化概述
  6. shell脚本详解(二)——条件测试、if语句和case分支语句
  7. 电脑不能打字_电脑拼音打字快速入门秘籍
  8. 计算机管理术语路径描述的是,directory
  9. axure如何实现跳转_Axure教程:网易云音乐首页原型设计
  10. cron表达式 每隔1个小时_2-1!1-1!短短51个小时,西班牙人获4大喜讯,天佑武磊...