技術分享

LeetCode

Leetcode

290. Word Pattern

290. Word Pattern

Leetcode 分享筆記290. Word Pattern題目 class Solution(object): def wordPattern(self, pattern, s): """ :type pattern: str :type s: str :rtype: bool """ # 切割文字成陣列 list_pattern = [str(word) for word in pattern] list_s = s.split(' ') # 將切割好的文字陣列轉成數字陣列,不同的文字對應道不同的數字,用Dict表示 i =...

35. Search Insert Position

35. Search Insert Position

Leetcode 分享筆記35. Search Insert Position題目 class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ # 找到數字即跳出索引,未找到數字則找到排序之索引 for i in range(0,len(nums)): if (nums[i] == target): return i if (i ==...

1. Two Sum

1. Two Sum

Leetcode 分享筆記1. Two Sum題目 class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ # 第一輪:第一個數字進去,後面一個一個加,如果等於目標物,即停止,否則,進行第二輪(第二個數字) i = 0 while(i < len(nums)): for j in range(i, len(nums)): total = 0 if...

21. Merge Two Sorted Lists

21. Merge Two Sorted Lists

Leetcode 分享筆記21. Merge Two Sorted Lists題目 class Solution(object): def mergeTwoLists(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ ans = ListNode(None) prev = ans while l1 and l2: if(l1.val <= l2.val): prev.next = l1 l1 = l1.next...

divider2 3 scaled

Get Instant Access to Financial News & Advice

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation

77 / 100