2. This is the 88 leetcode topic, topic is to merge two orderly array
3. Want to know why I have to run out, thank you!
CodePudding user response:
1. While to add a j
Def func (num1, num2) :
For I in range (len (num2) :
For j in range (len (num1) :
While j & lt; Len (num1) and num2 [I] & gt; Num1 [j] :
J=j + 1
Num1. Insert (j, num2 [I])
Break
Return the print (num1)
Nums1=[1, 2, 3]
Nums2=[6] 2
Func (nums1 nums2)
CodePudding user response:
The num1. Insert (j, num2 [I]) move forward and for alignment can not break
Def func (num1, num2) :
For I in range (len (num2) :
For j in range (len (num1) :
While j & lt; Len (num1) and num2 [I] & gt; Num1 [j] :
J=j + 1
Num1. Insert (j, num2 [I])
Return the print (num1)
Nums1=[1, 2, 3]
Nums2=[6] 2
Func (nums1 nums2)
CodePudding user response: