In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "C language how to delete nodes in the linked list". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "C language how to delete nodes in the linked list"!
Please write a function so that it can delete the given (not the end) node in a linked list, and you will only be given the node that is required to be deleted.
There is a linked list-- head = [4, 5, 5, 1, 9], which can be expressed as:
4-> 5-> 1-> 9
Example 1:
Input: head = [4, 5, 1, 10, 9], node = 5
Output: [4Jing 1JI 9]
Explanation: given the second node in your linked list with a value of 5, after calling your function, the linked list should become 4-> 1-> 9.
Example 2:
Input: head = [4pm 5pm 1je 9], node = 1
Output: [4, 5, 5, 9]
Explanation: given the third node in your linked list with a value of 1, after calling your function, the linked list should become 4-> 5-> 9.
Description:
The linked list contains at least two nodes.
The values of all nodes in the linked list are unique.
The given node is a non-trailing node and must be a valid node in the linked list.
Do not return any results from your function.
The question in the previous issue is: 165, the nearest common ancestor of the binary search tree
1public TreeNode lowestCommonAncestor (TreeNode root, TreeNode p, TreeNode Q) {
2 while ((root.val-p.val) * (root.val-q.val) > 0)
3 root = p.val < root.val? Root.left: root.right
4 return root
5}
Parsing:
It's easy to understand that as long as the while loop is true, then p and Q are either in the left subtree of root or in the right subtree of root, so keep looking. When the loop in while is false, then either p and Q are in the left subtree of root and the right subtree of root, or one of p and Q is the ancestor node of the other (when the front of the conditional statement in while equals 0). We can also change it to recursion.
1public TreeNode lowestCommonAncestor (TreeNode root, TreeNode p, TreeNode Q) {
2 return (root.val-p.val) * (root.val-q.val)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.