瀏覽分類:

極短篇 Status

百字左右的極短篇

[Py] Median of Two Sorted Arrays

Median of Two Sorted Arrays (leetcode.com)

2085 / 2085 test cases passed.
Status: Accepted
Runtime: 120 ms (19.98%)
Memory Usage: 14.1 MB

class Solution:
    def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
        n1n = len(nums1)
        n2n = len(nums2)
        if n1n == 0: # if num1 is empty
            if (n2n % 2) == 1: # Odd 
                return nums2[n2n//2]
            else:
                return (nums2[n2n//2]+nums2[(n2n//2)-1])/2
        elif n2n == 0 :# if num2 is empty
            if (n1n % 2) == 1: # Odd 
                return nums1[n1n//2]
            else:
                return (nums1[n1n//2]+nums1[(n1n//2)-1])/2
        else: # both are not empty
            Arr=[]
            n1i=0 #cursor1 for num1
            n2i=0 #cursor2 for num2
            while(n1i<n1n or n2i<n2n):
                if n1i >= n1n and n2i<n2n: #num1 is all added to new array
                    Arr.append(nums2[n2i])
                    n2i+=1
                    continue
                elif n1i<n1n and n2i>=n2n: #num2 is all added to new array
                    Arr.append(nums1[n1i])
                    n1i+=1
                    continue
                else: # both nums1 and nums2 have elements
                    if nums1[n1i] <= nums2[n2i]:
                        Arr.append(nums1[n1i])
                        n1i+=1
                        continue
                    else:
                        Arr.append(nums2[n2i])
                        n2i+=1
                        continue
            # After all elements added to new array, find the median.
            An = len(Arr)
            if (An%2)==1: #Odd
                return Arr[An//2]
            else:
                return (Arr[An//2]+Arr[(An//2)-1])/2

[筆記] FFmpeg 裁剪影片

本篇是一個使用 FFmpeg 裁剪影片的小筆記,主要參考自 stackoverflow 的問答

目的:

當已經使用剪輯軟體輸出好一個影片,而想要擷取一個影片片段,但又不想要重新編碼影片(花費很多時間),使用 FFmpeg 可以輕鬆完成這樣的要求。

使用軟體: FFmepg,跨平台的影片應用軟體,文件下載

閱讀更多

[Life] Never buy a cheap USB cable or it may burn down your home

I bought a very cheap (200 NTD) micro USB cable with measuring feature few weeks ago. It can measure the voltage and the amp when charging but I broke it after I turn the switch to USB mode when charging the power bank. Yesterday when I try to charge a exhausted power bank which supports QC3.0, it starts to swell and heat up quickly. I immediately turn of the switch after I smelled a malodor of burning plastic skin. Luckily nothing was lost except the cable. I cut the cable and found that the metal cables are so thin ( smaller than AWG30) that may cause some problems when conducting large voltage and current. I think I’ll mever buy a cheap USB cable in the future…