leetcode 3. Longest Substring Without Repeating Characters [java]
idea:
设置一个hashset存储非重复元素
j:遍历s
i:最近的一个非重复指针
注意点:
1.Set set = new HashSet<>();
2. add remove
public int lengthOfLongestSubstring(String s) {
int i = 0, j = 0, max = 0;
Set<Character> set = new HashSet<>();
while(j < s.length()){
if(! set.contains(s.charAt(j)) ){
set.add(s.charAt(j++));
max = Math.max(max, set.size());
}else{
set.remove(s.charAt(i++));
}
}
return max;
}
leetcode 3. Longest Substring Without Repeating Characters [java]的更多相关文章
- C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...
- 【JAVA、C++】LeetCode 003 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Java [leetcode 3] Longest Substring Without Repeating Characters
问题描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
- leetcode第三题Longest Substring Without Repeating Characters java
Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...
- [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...
- LeetCode 3 Longest Substring Without Repeating Characters 解题报告
LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...
- leetcode:Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- [LeetCode][Python]Longest Substring Without Repeating Characters
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...
随机推荐
- 开源方案搭建可离线的精美矢量切片地图服务-5.Mapbox离线项目实现
项目成果展示(所有项目文件都在阿里云的共享云虚拟主机上,访问地图可以会有点慢,请多多包涵). 01:中国地图:http://test.sharegis.cn/mapbox/html/3china.ht ...
- Word Reversal (简单字符串处理)
题目描述: For each list of words, output a line with each word reversed without changing the order of th ...
- 【Leetcode】292. Nim游戏
题目链接:https://leetcode-cn.com/problems/nim-game/description/ 您和您的朋友,两个人一起玩 Nim游戏:桌子上有一堆石头,每次你们轮流拿掉 1 ...
- Druid链接池配置加密密码链接数据库
Druid是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PROXOOL等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针对监控而生的DB ...
- vue-cli中全局组件的注册使用
一.全局注册 在install函数中全局注册组件,没毛病,老铁. 二.其它组件调用 直接在其他 .vue组件中直接写 <popup ref="popup">,然后就可 ...
- MVC的注意事项及开发技巧
演示产品源码下载地址:http://www.jinhusns.com
- EF 求和 GroupBy多个字段
GroupBy根据多个字段分组使用方式: 一.使用扩展方法 query.GroupBy(q => new { q.Year, q.Month }) .Select(q => new { Y ...
- mybatis将传入0识别成空字符串
mybatis将传入的Integer类型的0被识别成空字符串,网上的解决办法: <if test="status != null and status != '' or status ...
- 什么是 Spring AOP 和代理
https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_9403056301388627935% ...
- mongodb远程连接访问
随着云计算,云服务的不断发展演进,数据库的管理及维护方式也在转变,传统基于C/S客户端工具管理的方式,已经无法满足实际需要. TreeSoft数据库管理系统,采用web方式,对mongoDB,MySQ ...