当前位置:网站首页>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
}
边栏推荐
- [leetcode] most elements [169]
- 归并排序详解及应用
- Go multithreaded data search
- [chestnut sugar GIS] ArcScene - how to make elevation map with height
- boot actuator - prometheus使用
- Freshman learning sharing
- QT qsplitter splitter
- Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
- LC173. 二叉搜索树迭代器
- 2016. 增量元素之间的最大差值
猜你喜欢
mysql重置密码,忘记密码,重置root密码,重置mysql密码
Qt QProgressBar详解
Array advanced improvement
海思3559万能平台搭建:在截获的YUV图像上画框
[leetcode] reverse the word III in the string [557]
QT qsplitter splitter
The kth largest element in the [leetcode] array [215]
Chow-Liu Tree
Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code
Qt QScrollArea
随机推荐
Generics and reflection, this is enough
Jerry's charge unplugged, unable to touch the boot [chapter]
[Yangcheng cup 2020] easyphp
Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP
MySQL queries nearby data And sort by distance
Uniapp wechat login returns user name and Avatar
4 special cases! Schools in area a adopt the re examination score line in area B!
ServletContext learning diary 1
数据分析学习记录--用EXCEL完成简单的单因素方差分析
在SOUI里使用真窗口时使用SOUI的滚动条
解决Chrome浏览器和Edeg浏览器主页被篡改的方法
大一学习分享
[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM
实现BottomNavigationView和Navigation联动
Chow-Liu Tree
Methods to solve the tampering of Chrome browser and edeg browser homepage
归并排序详解及应用
Redis 过期策略+conf 记录
Solving ordinary differential equations with MATLAB
Learning records of data analysis (II) -- simple use of response surface method and design expert