当前位置:网站首页>Li Kou brush questions (2022-6-28)
Li Kou brush questions (2022-6-28)
2022-07-02 23:09:00 【Vegetable chicken with konjaku】
Reverse a linked list
Here's the head node of the list head , Please reverse the list , And return the inverted linked list .
Example 1:
Input :head = [1,2,3,4,5]
Output :[5,4,3,2,1]
Example 2:
Input :head = [1,2]
Output :[2,1]
Example 3:
Input :head = []
Output :[]
If you simply put the first 1 A node points to NULL, Will be the first 2 The first node points to the 1 The address of the node , Then we will lose the first 3 The address of the node , Therefore, it is impossible to 3 The first node points to the 2 Nodes . So we need three pointers .
ListNode* reverseList(ListNode* head) {
ListNode *p =nullptr;
ListNode *tmp;
while(head){
tmp = head->next;
head->next = p;
p = head;
head = tmp;
}
return p;
}
The longest string without duplicate 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.
Example 2:
Input : s = "bbbbb"
Output : 1
explain : Because the longest substring without repeating characters is "b", So its length is 1.
Example 3:
Input : s = "pwwkew"
Output : 3
explain : Because the longest substring without repeating characters is "wke", So its length is 3.
Please note that , Your answer must be Substring The length of ,"pwke" Is a subsequence , Not substring .
Specify left and right positions , Move the left pointer one space to the right , Indicates to start enumerating the next character as the starting position , And then we can keep moving the right pointer to the right , But we need to ensure that there are no duplicate characters in the substring corresponding to these two pointers . At the end of the move , This substring corresponds to the longest substring that does not contain repeated characters starting with the left pointer .
public int lengthOfLongestSubstring(String s) {
int len = s.length();
if(len == 0) return 0;
int start = 0 , end = 0;
int ret = 0;// Substring length
while(end < len){
for(int j = start ; j < end ; j++){
if(s.charAt(j) == s.charAt(end)){// At present end The subscript character and subscript are j When the characters are the same
ret = Math.max(ret , end - start);// Find the maximum substring length
start = j + 1;// slide start Just go to the end of the repeating character
}
}
end++;// There are no duplicate characters , that end Move backward , Lengthen the window length to continue a new round of traversal comparison
}
return Math.max(ret , end - start);// Make a final comparison
}
边栏推荐
- [chestnut sugar GIS] ArcScene - how to make elevation map with height
- Niuke network: maximum submatrix
- 20220527_数据库过程_语句留档
- 门牌制作 C语言
- 数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
- 设置单击右键可以选择用VS Code打开文件
- [adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)
- 实现BottomNavigationView和Navigation联动
- ping域名报错unknown host,nslookup/systemd-resolve可以正常解析,ping公网地址通怎么解决?
- 1px pixel compatibility of mobile terminal, 1px border
猜你喜欢
![[leetcode] reverse the word III in the string [557]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode] reverse the word III in the string [557]

Xshell configuration xforward forwarding Firefox browser

Mask R-CNN

阿里云有奖体验:如何使用 PolarDB-X

Strictly abide by the construction period and ensure the quality, this AI data annotation company has done it!

聊聊内存模型与内存序

Go语言sqlx库操作SQLite3数据库增删改查
![[Yangcheng cup 2020] easyphp](/img/12/da28f738e50e625b0a66a94af3703d.png)
[Yangcheng cup 2020] easyphp

Redis 过期策略+conf 记录

Webrtc audio and video capture and playback examples and mediastream media stream analysis
随机推荐
解决Chrome浏览器和Edeg浏览器主页被篡改的方法
最小生成树 Minimum Spanning Tree
Analyse des données dossiers d'apprentissage - - analyse simple de la variance à facteur unique avec Excel
用matlab调用vs2015来编译vs工程
Chow-Liu Tree
Pytorch training CPU usage continues to grow (Bug)
创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
Potplayer set minimized shortcut keys
[npuctf2020]ezlogin XPath injection
Loss function~
地平线2022年4月最新方案介绍
深度剖析数据在内存中的存储----C语言篇
Splunk audit setting
PotPlayer设置最小化的快捷键
PMP project integration management
[chestnut sugar GIS] ArcScene - how to make elevation map with height
Higher order operation of bits
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
Mask R-CNN
20220524_数据库过程_语句留档