Home > other >  Everyone a great god can help me check my python code where is wrong? How to change?
Everyone a great god can help me check my python code where is wrong? How to change?

Time:09-29

1. Errors is: is on the line, while an array subscript crossing the line, I also don't understand where is wrong, please!
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 j2. Each value after the insert 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])
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:

reference 1/f, ice wind of reply:
1. While to add a j2. Each value after the insert 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])
Break
Return the print (num1)

Nums1=[1, 2, 3]
Nums2=[6] 2
Func (nums1 nums2)
wow! I try, thank you!
  • Related