当前位置:网站首页>Sword finger offer 52. The first common node of the two linked lists
Sword finger offer 52. The first common node of the two linked lists
2022-07-24 19:27:00 【nsq1101】
subject
Enter two linked lists , Find their first common node .
Like the two linked lists below :

At the node c1 Start meeting .
Example 1:

Input :intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
Output :Reference of the node with value = 8
Enter an explanation : The value of the intersection node is 8 ( Be careful , Cannot be if two lists intersect 0). Starting from the respective heads , Linked list A by [4,1,8,4,5], Linked list B by [5,0,1,8,4,5]. stay A in , There is... Before the intersection node 2 Nodes ; stay B in , There is... Before the intersection node 3 Nodes .
Ideas
- The journey is the same ,A End of traversal , Traverse B;B End of traversal , Traverse A, Nodes of the same length are the same
Program
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
A ,B = headA,headB
while A != B :
A = A.next if A else headB
B = B.next if B else headA
return A
边栏推荐
- 拦截器和过滤器
- PCIe link initialization & Training
- Getaverse, a distant bridge to Web3
- JVM method call
- On July 31, 2022, the dama-cdga/cdgp data governance certification class was opened!
- Common methods of string class
- Tupu software digital twin civil aviation flight networking, building a new business form of smart Civil Aviation
- LTSpice software power settings
- Literature reading: gopose 3D human pose estimation using WiFi
- Database index: index is not a panacea
猜你喜欢

C # shelling tool for code encryption protection

Original reverse compensation and size end

In the spring of domestic databases
![[laser principle and application -6]:q switching element and Q drive circuit board](/img/30/e199b73fb9b0ad335f26f2378cfc45.png)
[laser principle and application -6]:q switching element and Q drive circuit board

Convolutional Neural Networks in TensorFlow quizs on Coursera

Description of large and small end mode

【JVM学习04】JMM内存模型

Biopharmaceutical safety, power supply and production guarantee

Analysis of the basic concept of digital warehouse

Emergency lighting design of large stadiums and gymnasiums
随机推荐
Detailed explanation of ELF format (I)
[understanding of opportunity-48]: Guiguzi - Chapter 7 - collect information in advance, make predictions and implementation plans in advance
OpenGL learning (V) modern OpenGL triangle rendering
Mysql database, de duplication, connection
Getaverse, a distant bridge to Web3
Free and open source website navigation source code collection, sorting and summary - self built personal navigation Homepage
Cmake series tutorial 2 HelloWorld
OpenGL learning (III) glut two-dimensional image rendering
[laser principle and application -6]:q switching element and Q drive circuit board
[question 39] special question for Niuke in-depth learning
This visual analysis library makes it easy for you to play with data science!
Day 9 (this keyword and experiment)
Solve the problem of disconnection due to long idle time after SSH login
The ark compiler is coming. What about APK reinforcement
[in depth study of 4g/5g/6g topic -39]: urllc-10 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -3- how to distinguish urllc services? Detailed expl
Detailed explanation of the relationship between MySQL tables
Rotation matrix derivation process
Ebpf verifier
Anaconda installs labelimg (super simple and available)
Those gods on Zhihu reply