[問題] Leetcode 88. Merge Sorted Array
這一題給定nums1, nums2兩個list,以及m,n代表這兩個list的長度,
然後題目規定要把兩個用merge的方式存到nums1。
想說先直接sort測試看看,以下是我的程式碼:
class Solution(object):
def merge(self, nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: void Do not return anything, modify nums1 in-place instead.
"""
nums = nums1 + nums2
nums.sort()
nums1 = nums
但這個程式碼在下面的測資出現問題:
Input: [0], 0, [1], 1
Output: [0]
Expected: [1]
感覺,我的output應該是[0,1]才對,
但我不懂的是為什麼明明nums1有一個[0]的元素,長度卻是0?
後來又在跑自定的測資
Input: [0],1,[1],1
Your Answer: [0]
Expected answer: Line 16: IndexError: list assignement index out of range
我的程式只有寫到13行,是不是他題目有點奇怪啊?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.214.132
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1468548902.A.FB0.html
→
07/15 10:26, , 1F
07/15 10:26, 1F
→
07/17 09:23, , 2F
07/17 09:23, 2F
→
07/17 16:19, , 3F
07/17 16:19, 3F
→
07/17 21:20, , 4F
07/17 21:20, 4F
→
07/17 21:26, , 5F
07/17 21:26, 5F
→
07/17 21:27, , 6F
07/17 21:27, 6F
→
07/17 21:28, , 7F
07/17 21:28, 7F
→
07/17 21:28, , 8F
07/17 21:28, 8F
→
07/17 21:41, , 9F
07/17 21:41, 9F
Python 近期熱門文章
PTT數位生活區 即時熱門文章