Leetcode
Muqianli
这个作者很懒,什么都没留下…
展开
-
Leetcode-999. Available Captures for Rook
—Easyhttps://leetcode.com/problems/available-captures-for-rook/Code:class Solution: def numRookCaptures(self, board) -> int: ans_cnt = 0 m = len(board) n = len(b...原创 2019-03-01 10:21:09 · 349 阅读 · 0 评论 -
617. Merge Two Binary Trees
—Easyhttps://leetcode.com/problems/merge-two-binary-trees/Code:class TreeNode(object): def __init__(self,x): self.val = x self.left = None self.right = Noneclas...原创 2019-04-02 09:55:46 · 154 阅读 · 0 评论 -
852. Peak Index in a Mountain Array
—Easyhttps://leetcode.com/problems/peak-index-in-a-mountain-array/Code:class Solution: def peakIndexInMountainArray(self, A) -> int: ans_flag = False for i in range(...原创 2019-04-04 10:13:16 · 194 阅读 · 0 评论 -
944. Delete Columns to Make Sorted
—Easyhttps://leetcode.com/problems/delete-columns-to-make-sorted/Code:class Solution: def minDeletionSize(self, A) -> int: ans = [1]*len(A[0]) tmp = A[0] for...原创 2019-03-10 17:16:18 · 140 阅读 · 0 评论 -
461. Hamming Distance
—Easyhttps://leetcode.com/problems/hamming-distance/Code:class Solution: def hammingDistance(self, x: int, y: int) -> int: ans = 0 X = list(map(int,list(bin(x).replace...原创 2019-03-10 16:30:22 · 175 阅读 · 0 评论 -
942. DI String Match
—Easyhttps://leetcode.com/problems/di-string-match/class Solution: def diStringMatch(self, S: str) : N = len(S) list_ans = [] start = 0 end = N fo...原创 2019-03-10 11:18:37 · 174 阅读 · 0 评论 -
657. Robot Return to Origin
—Easyhttps://leetcode.com/problems/robot-return-to-origin/Code:class Solution: def judgeCircle(self, moves: str) -> bool: count_h = 0 count_v = 0 for char in m...原创 2019-03-10 11:02:34 · 193 阅读 · 0 评论 -
Leetcode-832. Flipping an Image
—Easyhttps://leetcode.com/problems/flipping-an-image/Code:class Solution: def flipAndInvertImage(self, A) : ans_ma = [] for ls in A: ls = ls[::-1] ...原创 2019-03-03 11:37:14 · 173 阅读 · 0 评论 -
Leetcode-709. To Lower Case
—Easyhttps://leetcode.com/problems/to-lower-case/Code: class Solution: def toLowerCase(self, str: str) -> str: s = str.lower() return s# s = Solution()# print(s.to...原创 2019-02-26 20:42:44 · 187 阅读 · 0 评论 -
Leetcode-929. Unique Email Addresses
—Easyhttps://leetcode.com/problems/unique-email-addresses/Code: class Solution: def numUniqueEmails(self, emails) -> int: new_em = [] for elt in emails: i...原创 2019-02-26 18:29:34 · 222 阅读 · 0 评论 -
Leetcode-771. Jewels and Stones
—Easyhttps://leetcode.com/problems/jewels-and-stones/Code: class Solution: def numJewelsInStones(self, J, S): ans = 0 for elt in S : if elt in J: ...原创 2019-02-26 15:30:18 · 172 阅读 · 0 评论 -
Leetcode-463. Island Perimeter
—Easyhttps://leetcode.com/problems/island-perimeter/ Code: class Solution: def islandPerimeter(self, grid) : sum_count = 0 if len(grid) == 0: return 0 ...原创 2019-02-25 20:32:43 · 199 阅读 · 0 评论 -
Leetcode-905. Sort Array By Parity
—Easyhttps://leetcode.com/problems/sort-array-by-parity/Code:class Solution: def sortArrayByParity(self, A ): ans_ls_even = [] ans_ls_odd = [] for elt in A: ...原创 2019-03-01 15:01:12 · 288 阅读 · 0 评论 -
Leetcode-977. Squares of a Sorted Array
—Easyhttps://leetcode.com/problems/squares-of-a-sorted-array/Code:class Solution: def sortedSquares(self, A) : ans_list = [] for elt in A: ans_list.append(elt...原创 2019-03-01 14:52:37 · 259 阅读 · 0 评论 -
Leetcode-961. N-Repeated Element in Size 2N Array
—Easyhttps://leetcode.com/problems/n-repeated-element-in-size-2n-array/Code:class Solution: def repeatedNTimes(self, A) -> int: list_number = [] for elt in A: ...原创 2019-03-01 11:29:12 · 160 阅读 · 0 评论 -
Leetcode-804. Unique Morse Code Words
—Easyhttps://leetcode.com/problems/unique-morse-code-words/Code:class Solution: def uniqueMorseRepresentations(self, words) -> int: dict_umcw = {'a':".-",'b':"-...",'c':"-.-.",...原创 2019-03-01 11:04:22 · 171 阅读 · 0 评论 -
728. Self Dividing Numbers
—Easyhttps://leetcode.com/problems/self-dividing-numbers/Code:class Solution(object): def selfDividingNumbers(self, left: int, right: int) : ans_list = [] for i in rang...原创 2019-04-02 10:13:47 · 224 阅读 · 0 评论