avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

1669. Merge two linked watches One question daily

  2024-01-01        
字数统计: 163字   |   阅读时长: 1min

topic:

1675057199631.png
1669. Merge two linked watches

Thought:

直接放上官方answer了,就yes模拟Linked。

topic要求将 list1
First a arrive b Delete all nodes,Replace it for list2
。therefore,我们首先找arrive list1
B a−1 Node preA,As well as b+1 Node aftB。because 1≤a≤b<n−1
(in n yes list1 length),so preA and aftB yes一定存在of。

Then we let us give up preA of next direction list2
of头节点,Give up list2
of尾节点of next direction aftB To。

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:
preA = list1
for _ in range(a-1):
preA = preA.next
preB = preA
for _ in range(b - a + 2):
preB = preB.next
preA.next = list2
while list2.next:
list2 = list2.next
list2.next = preB
return list1
  • Python
  • answer
  • One question daily
  • Linked

扫一扫,分享到微信

微信分享二维码
1663. The smallest string with a given value One question daily
1798You can construct the maximum number of continuity One question daily
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code:

153 篇 | 133k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号