当前位置:网站首页>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
}
边栏推荐
- Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
- Jerry's prototype will trigger shutdown after multiple touches [chapter]
- The motivation of AES Advanced Encryption Protocol
- 深度剖析数据在内存中的存储----C语言篇
- 编辑卡顿
- Kubernetes uses the host name to allocate the pod on the specified node
- 移动端 1px 像素兼容性问题,实现1px 边框
- boot actuator - prometheus使用
- Value sequence < detailed explanation of daily question >
- easyclick,ec权朗网络验证源码
猜你喜欢

Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP

Generics and reflection, this is enough

Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
![[Solved] Splunk: Cannot get username when all users are selected“](/img/13/1e824c8005701e21fc5b4e73308d53.png)
[Solved] Splunk: Cannot get username when all users are selected“

Loss function~
![[NPUCTF2020]ezlogin xPATH注入](/img/6e/dac4dfa0970829775084bada740542.png)
[NPUCTF2020]ezlogin xPATH注入

程序员版本的八荣八耻~

Lambda expression: an article takes you through
![[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)](/img/a3/d8421ea1539eba08bf7a5a629d92e6.jpg)
[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)

海思3559万能平台搭建:在截获的YUV图像上旋转操作
随机推荐
AES高级加密协议的动机阐述
boot actuator - prometheus使用
剑指 Offer II 099. 最小路径之和-双百代码
设置单击右键可以选择用VS Code打开文件
成功改变splunk 默认URL root path
Minimum spanning tree
Go语言sqlx库操作SQLite3数据库增删改查
Kubernetes uses the host name to allocate the pod on the specified node
密码技术---分组密码的模式
[Solved] Splunk: Cannot get username when all users are selected“
损失函数~
海思3559万能平台搭建:在截获的YUV图像上画框
P7072 [csp-j2020] live broadcast Award
MySQL reset password, forget password, reset root password, reset MySQL password
Potplayer set minimized shortcut keys
海思调用接口之Makefile配置
Higher order operation of bits
Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
Mask R-CNN