Leecode 3.无重复字符的最大字串长度(Java 暴力拆解)


1 class Solution {
2 public int lengthOfLongestSubstring(String s) {
3 int left=0;int right = 0;int length = 0;int maxLength = 0;
4 Set setList = new HashSet<>();
5 char[] chars = s.toCharArray();
6 while(right<(chars.length)){//一直到right增加到小于string的长度
7 if(!setList.contains(chars[right])){
8 setList.add(chars[right]);
9 //如果setList中没有此时string中right下标的元素就把他加入setList
10 right++;//向右移动
11 length++;
12 if(length>maxLength){//如果此时长度大于最大长度,就更新最大长度
13 maxLength = length;
14 }
15
16
17 }else{//如果有重复,就移动left直至没重复
18 while(setList.contains(chars[right])){
19 setList.remove(chars[left]);
20 left++;
21 length--;
22 }
23 }
24 }
25 return maxLength;
26 }
27 }
Leecode 3.无重复字符的最大字串长度(Java 暴力拆解)的更多相关文章
- LeetCode03 - 无重复字符的最长子串(Java 实现)
LeetCode03 - 无重复字符的最长子串(Java 实现) 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/longest-substri ...
- LeetCode: 3 无重复字符的最长子串 (Java)
3. 无重复字符的最长子串 https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ 最初始的解 ...
- leetcode刷题笔记-3. 无重复字符的最长子串(java实现)
题目描述 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "ab ...
- [LeetCode]3.无重复字符的最长子串(Java)
原题地址: longest-substring-without-repeating-characters/submissions 题目描述: 示例 1: 输入: s = "pwwkew&qu ...
- lintcode: 最长无重复字符的子串
题目 最长无重复字符的子串给定一个字符串,请找出其中无重复字符的最长子字符串. 例如,在"abcabcbb"中,其无重复字符的最长子字符串是"abc",其长度为 ...
- leetcode刷题第三天<无重复字符的最长子串>
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 : 输入: "abcabcbb" 输出: 解释: 因为无重复字符的最长子串是 . 示例 : 输入: &quo ...
- [Swift]LeetCode3. 无重复字符的最长子串 | Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- [LeetCode] 3. 无重复字符的最长子串
题目链接:(https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) 题目描述: 给定一个字符 ...
- day4——无重复字符的最长子串
// 小白一名,0算法基础,艰难尝试算法题中,若您发现本文中错误, 或有其他见解,往不吝赐教,感激不尽,拜谢. 领扣 第2题 今日算法 题干 //给定一个字符串,请你找出其中不含有重复字符的 最长子串 ...
- leetcode 刷题(3)--- 无重复字符的最长子串
给定一个字符串,找出不含有重复字符的最长子串的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 无重复字符的最长子串是 "abc",其长度为 ...
随机推荐
- vue 打开页面触发事件
vue中created(),mounted()与activated()区别及应用 created():在创建vue对象时,当html渲染之前就触发:但是注意,全局vue.js不强制刷新或者重启时只创建 ...
- stm32f030 模拟IIC
#define read_SDA (GPIOA->IDR&GPIO_Pin_10) >>10 //PA10 SDA#define set_SDA GPIO_SetBits(G ...
- 几款Android 应用自动化测试工具
本文转自:https://blog.csdn.net/hebbely/article/details/78901466 简述: 本文介绍几款流行的 Android应用自动化测试工具. Monkey测试 ...
- Angular前端调用asp.net core web api后端,报跨域问题
在 ASP.NET Core 中启用跨域请求 (CORS) https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnet ...
- eggjs中egg-mysql不支持mysql集群,代码修改为支持集群
说明:暂不支持egg-mysql动态数据源,用到动态数据源请自行修改.欢迎各位大佬指导... 集群配置: exports.mysql = { // 单数据库信息配置 client: { db1: { ...
- 比较有趣的C语言小程序
1.判断是否是闰年: #include <stdio.h> int main(void) { int year, a; printf("Please enter ...
- Unity中实现在规定时间内从一个值递增到另一个值
1.进度条(在规定时间内完成进度条) private Image progressBar; private float currentProgress = 0; /// <summary> ...
- JAVA框架入门理解
一:关于java开发的框架我们可以先从java web开发框架的变迁来给大家简单叙述一下: 1 SSH --Struts+Spring+Hibernate 2 Spring +SpringMVC + ...
- Vue.js + TypeScript 项目构建
一:全局安装vue/cli npm install -g @vue/cli安装完成后检查版本vue --version 二:构建项目创建文件 vue create projectName 有的刚开始 ...
- SpringBoot整合其他框架
SpringBoot整合Junit 实现步骤 搭建SpringBoot工程 引入starter-test起步依赖 编写测试类 添加测试相关注解 @RunWith(SpringRunner.class) ...