当前位置:网站首页>HOT100 hash
HOT100 hash
2022-07-26 07:25:00 【wzf6667】
- Longest substring without repeating characters
Given a string s , Please find out that there are no duplicate characters in it Longest substrings The length of .
Example 1:
Input : s = “abcabcbb”
Output : 3
explain : Because the longest substring without repeating characters is “abc”, So its length is 3.
Use sliding windows , The specific algorithm is :
for In circulation i Is the right value of the window , Set an lvalue to 0, If the current window does not contain duplicate elements , Then the right boundary slides to the right , If you include , Then the left boundary is the position of the repeating element plus 1.
Notice when selecting the left boundary , The current character is not contained in the current longest valid sub segment , Such as :abba, Let's add a,b Into the map, here left=0, Let's add b, Find out map Contained in the b, and b Included in the longest valid sub segment , Namely 1) The situation of , We update left=map.get(b)+1=2, At this time, the sub segment is updated to b, and map It still contains a,map.get(a)=0; And then , We traverse to a, Find out a Included in map in , And map.get(a)=0, If we look like 1) Handle it the same way , You will find left=map.get(a)+1=1, actually ,left here It should remain the same ,left Always be 2, Sub segment becomes ba That's right .
class Solution {
public int lengthOfLongestSubstring(String s) {
Map<Character,Integer> map = new HashMap<>();
int max = 0;
int left = 0;
for(int i = 0; i < s.length();i++){
if(map.containsKey(s.charAt(i))){
left = Math.max(left,map.get(s.charAt(i))+1);
}
max = Math.max(max,i-left+1);
map.put(s.charAt(i),i);
}
return max;
}
}
- Letter combination of telephone number
Given a number only 2-9 String , Returns all the letter combinations it can represent . You can press In any order return .
The mapping of numbers to letters is given as follows ( Same as phone key ). Be careful 1 Does not correspond to any letter .
Example 1:
Input :digits = “23”
Output :[“ad”,“ae”,“af”,“bd”,“be”,“bf”,“cd”,“ce”,“cf”]
Recursive backtracking
Be careful add No need to delete after completion letters The last letter
class Solution {
public List<String> letterCombinations(String digits) {
List<String> combinations = new ArrayList<String>();
if (digits.length() == 0) {
return combinations;
}
Map<Character, String> phoneMap = new HashMap<Character, String>() {
{
put('2', "abc");
put('3', "def");
put('4', "ghi");
put('5', "jkl");
put('6', "mno");
put('7', "pqrs");
put('8', "tuv");
put('9', "wxyz");
}};
digui(combinations,phoneMap,digits,0,new StringBuffer());
return combinations;
}
public void digui(List<String> combinations,Map<Character, String> phoneMap,String digits, int index, StringBuffer letters){
if(index == digits.length()){
combinations.add(letters.toString());
return;
}
String content = phoneMap.get(digits.charAt(index));
for(int i = 0; i < content.length(); i++){
char c = content.charAt(i);
letters.append(c);
digui(combinations,phoneMap,digits,index+1,letters);
letters.deleteCharAt(index);
}
}
}
边栏推荐
- Hcip - MPLS Technology
- In July, glassnode data showed that the open position of eth perpetual futures contract on deribit had just reached a one month high of $237959827.
- Opencv learning basic functions
- Taishan Office Technology Lecture: page width, height, size and source, and the conversion relationship between inches, centimeters and DPI
- QT: modal, modeless, text box, button, single line input box
- 时间序列分析预测实战之ARIMA模型
- WCF 入门教程二
- dcn(deep cross network)三部曲
- C# 使用Log4Net记录日志(基础篇)
- Examples of financial tasks: real-time and offline approval of three scenarios and five optimizations of Apache dolphin scheduler in Xinwang bank
猜你喜欢

Network Trimming: A Data-Driven Neuron Pruning Approach towards Efficient Deep Architectures论文翻译/笔记
![[200 opencv routines] 231. Gray level co-occurrence matrix (GLCM) for feature description](/img/34/082364611754b5d2ede5ac2f3a42cc.png)
[200 opencv routines] 231. Gray level co-occurrence matrix (GLCM) for feature description

Airiot IOT platform enables the container industry to build a welding station information monitoring system

C51与MDK共存 Keil5安装教程

Apache dolphin scheduler & tidb joint meetup | focus on application development capabilities under the development of open source ecosystem

达人专栏 | 还不会用 Apache Dolphinscheduler?大佬用时一个月写出的最全入门教程【三】

PG operation and maintenance -- logical backup and physical backup practice

Apache dolphin scheduler version 3.0.0-beta-1 was released, and flinksql and Zeppelin task types were added

NFT digital collection system development: the collision of literature + Digital Collections

:app:checkDebugAarMetadata 2 issues were found when checking AAR metadata: 2 issues were found when
随机推荐
C51 and MDK coexist keil5 installation tutorial
机器学习相关比赛网站
Apache DolphinScheduler&TiDB联合Meetup | 聚焦开源生态发展下的应用开发能力
Embedded development: tools -- intelligent watchdog design
6. Combined data type
Qt:列表框、表格、树形控件
Comparison and difference between dependence and Association
Apache DolphinScheduler 2.X保姆级源码解析,中国移动工程师揭秘服务调度启动全流程
Apache dolphin scheduler version 3.0.0-beta-1 was released, and flinksql and Zeppelin task types were added
Introduction to C language -- summary table of operator priority sorting
Relevant configurations of pychart: change font style and size, change picture background, and change the font color of console output
HCIP---MPLS详解和BGP路由过滤
6、MySQL数据库的备份与恢复
WPS or office compression of ppt
Performance test -- lockust performs seckill business scenario test
WCF 部署在IIS上
[yiku] wonderful! This library organization NPM script is simply explosive!
Airiot IOT platform enables the container industry to build a welding station information monitoring system
NFT数字藏品系统开发:数字藏品赋予品牌新活力
How to convert multi row data into multi column data in MySQL