Answer the question
In order to leave comments, you need to log in
How to write code in python?
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
Remarks:
The number of elements initialized in nums1 and nums2 is m and n respectively.
You can assume that nums1 has enough space (size greater than or equal to m + n) to store additional elements from nums2.
Example:
Input:
nums1 = [1,2,3,0,0,0], m = 3
nums2 = [2,5,6], n = 3
Output: [1,2,2,3,5, 6] #enter
numbers
nums1 = input("Enter numbers separated by spaces: ").split()
nums2 = input("Enter more numbers separated by spaces: ").split()
#sorting
nums1.sort()
nums2.sort()
#adding lists
a = (f"{nums1 + nums2}")
you need to somehow remove the zeros (as in my undercode), sort and display the result [1,2,2,3,5,6] as I understand it. And not ['0', '0', '0', '1', '2', '3', '2', '5', '6'] as in my code
and how to write so that you do not have to through enter a space, let's say the same numbers 1 2 3 0 0 0 and 2 5 6
Answer the question
In order to leave comments, you need to log in
>>> nums1 = input("Введите числа: ")
Введите числа: 123000
>>> nums1 += input("Введите ещё числа: ")
Введите ещё числа: 256
>>> nums1
'123000256'
>>> nums1 = [int(i) for i in nums1 if i != '0']
>>> nums1
[1, 2, 3, 2, 5, 6]
>>> nums1.sort()
>>> nums1
[1, 2, 2, 3, 5, 6]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question