lettcode
m0_37770463
这个作者很懒,什么都没留下…
展开
-
String to Integer
String to Integer:读取空格 读取 字符 读取数据计算判断是否达到极限A. >7 || >=7 || >6 || >=8B. >8 || >=8 || >7 || >=9____________ > 7 为统一解class Solution:def myAtoi(self, str: str) -> int:...原创 2019-03-14 09:53:36 · 71 阅读 · 0 评论 -
Powerful Integers
import mathclass Solution(object): def powerfulIntegers(self, x, y, bound): pow = [] x1 = int(math.log(bound, x)) if x!=1 else 1 y1 = int(math.log(bound, y)) if y!=1 else ...原创 2019-03-25 15:13:19 · 166 阅读 · 0 评论 -
Validate Binary Search Tree
描述的树的中序历遍有改进方法class Solution(object): def isValidBST(self, root): self.list = [] self.inorder(root) for index in range(1, len(self.list)): if self.list[index] &l...原创 2019-03-30 15:18:32 · 59 阅读 · 0 评论 -
Fair Candy Swap
import mathclass Solution(object):def fairCandySwap(self, A, B):“”":type A: List[int]:type B: List[int]:rtype: List[int]“”"if not A or not B:return []A_sum = sum(A)B_sum = sum(B)result = A...原创 2019-03-27 10:45:58 · 160 阅读 · 0 评论 -
Uncommon Words from Two Sentences
只出现过一次#Uncommon Words from Two Sentencesclass Solution(object): def uncommonFromSentences(self, A, B): """ :type A: str :type B: str :rtype: List[str] """...原创 2019-03-27 10:47:01 · 164 阅读 · 0 评论 -
Repeated DNA Sequence
字典存储一下class Solution(object): def findRepeatedDnaSequences(self, s): """ :type s: str :rtype: List[str] """ if len(s) <= 10: return [] ...原创 2019-04-01 16:47:30 · 116 阅读 · 0 评论 -
Merge Two Binary Trees
功能驱动迭代class Solution(object): def mergeTrees(self, t1, t2): if not t1 and not t2: return if t1 and not t2: return t1 if t2 and not t1: return t2 t1.val = t1....原创 2019-03-28 15:29:22 · 148 阅读 · 0 评论 -
Odd Even Linked List
感觉写的还不错 好多坑 PYTHON 居然有next 保护 神奇class ListNode(object): def __init__(self, x): self.val = x self.next = Noneclass Solution(object): def oddEvenList(self, head): if head == None: ...原创 2019-06-12 00:41:02 · 74 阅读 · 0 评论 -
Range Sum Query - Immutable
不占用另存资源破坏原有数据class NumArray(object): def __init__(self, nums): self.sums = nums for i in range(1, len(nums)): self.sums[i] += self.sums[i-1] def sumRange(self, i, j): if...原创 2019-06-12 09:00:37 · 72 阅读 · 0 评论 -
Univalued Binary Tree
class Solution(object): def isUnivalTree(self, root): if root == None: return True if self.Methon(root, root.val) == True: return False return True de...原创 2019-03-25 11:58:16 · 51 阅读 · 0 评论 -
Smallest Range I
看清楚题 想清楚思路再写吧class Solution(object): def smallestRangeI(self, A, K): return max(max(A)-min(A)-2*K,0)原创 2019-03-20 13:43:44 · 86 阅读 · 0 评论 -
two sum
class Solution:def twoSum(self, nums, target):“”":type nums: List[int]:type target: int:rtype: List[int]“”"for i, num in enumerate(nums):reset = target - numrest_list = nums[i+1:]if reset in...原创 2019-03-14 11:35:16 · 75 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
class Solution:def lengthOfLongestSubstring(self, s: str) -> int:left = 0right =0res = 0chars = dict()for right in range(len(s)):if s[right] in chars:left = max(chars[s[right]]+1, left)cha...原创 2019-03-14 13:55:47 · 57 阅读 · 0 评论 -
Next Permutation
class Solution: def nextPermutation(self, nums):if len(nums) <= 1: return numspartition = -1for i in range(len(nums)-2, -1, -1):if nums[i] < nums[i+1]:partition = ibreakif partition ==...原创 2019-03-14 22:00:26 · 57 阅读 · 0 评论 -
Remove Element
class Solution: def removeElement(self, nums: List[int], val: int) -> int: j = len(nums) - 1 for i in range(len(nums)-1,-1, -1): if nums[i] == val: nums[j],nums[i]=nums[i...原创 2019-03-14 22:34:05 · 120 阅读 · 0 评论 -
Path Sum
递归深度搜索一下就可以了class Solution: def hasPathSum(self, root, sum) -> bool: if root == None: return False if root.left == None and root .right == None: return root.val == sum ...原创 2019-03-19 22:31:52 · 48 阅读 · 0 评论 -
Maximum Depth of Binary Tree
最大深度遍历每一个点 递归最easy了class Solution:def maxDepth(self, root):if root == None:return 0return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))原创 2019-03-19 22:47:04 · 57 阅读 · 0 评论 -
Linked List Cycle
成环 dict 内存 判断class Solution(object): def hasCycle(self, head): map = {} while head: if id(head) in map: return True map[id(head)] = True head = head.next return False...原创 2019-03-20 10:23:50 · 56 阅读 · 0 评论 -
Verifying an Alien Dictionary
字典排序:理解错了 以为每个单词都要排序 那就不用isWordOk 那个def了class Solution(object): def isAlienSorted(self, words, order): dict = {} for index in range(len(order)): dict[order[index]] = index if...原创 2019-03-20 13:30:38 · 130 阅读 · 0 评论 -
413. 等差数列划分
都是连续的 数组才 ++动态规划 注意边界值class Solution(object): def numberOfArithmeticSlices(self, A): sizeof_input = len(A) if sizeof_input < 3: return 0 dp = [0] * sizeof_...原创 2019-07-29 12:48:20 · 91 阅读 · 0 评论