class solution:
defaultTwoLists(self, list1: Optional [ListNode], list2: Optional [ListNode] - > Optional [ListNode]:
cur=dummy=ListNode()
while list1 and list2:
if list1.val<list2.val:
cur.next=list1
list1, cur=list1.next, list1
else:
cur.next=list2
list2, cur=list2.next, list2
if list1 or list2:
cur.next=list1 if list1 else list2
return dummy.next
Merge consolidated lists sorted by leetcode.
A consolidated list with list1 and list2.
Sorry for the rudimentary question, but what does while list1 and list2: mean?
Do you mean list1 and list2 are Boolean values?
From docs.python.org embedded
truth determination
Any object can be determined as a true value and can be used as a condition for if
or while
or as an operator for the following Boolean operations:
The object is determined to be true by default.However, if the class defines the __bool__()
method and it returns False
, or if it defines the _len__()
method and it returns 0
, it is considered false.Here are some of the key embedded objects that are considered false:
None
and False
0
, 0.0
, 0j
, Decimal(0)
, Fraction(0,1)
'
, ()
, [ ]
, {}
, set()
, range(0)
boole operation---and
, or
, not
The Boolean operations are listed in descending order of priority:
as described above
Some objects determine False
In the case of questions, according to the definition of ListNode()
, if the linked list does not continue, it is considered false
© 2024 OneMinuteCode. All rights reserved.