楼主: Myron2017
跳转到指定楼层
上一主题 下一主题
收起左侧

刷题记录帖子

🔗
 楼主| Myron2017 2021-7-14 06:35:07 | 只看该作者
全局:
162        Find Peak Element
BInary Search 化用
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-7-14 14:26:41 | 只看该作者
全局:
205        Isomorphic Strings        Easy

多种解法,

(1) Two Dict Mapping
(2) First Occurance FingerPrint
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-7-14 15:08:38 | 只看该作者
全局:
791        Custom Sort String

简单 Application 题
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-7-14 16:41:18 | 只看该作者
全局:
295        Find Median from Data Stream        Hard        5        Classic Using Two Heap for Partion

  1. class MedianFinder(object):

  2.     def __init__(self):
  3.         """
  4.         initialize your data structure here.
  5.         """
  6.         # small to large
  7.         # pop large by multiplying -1
  8.         self.Heap1 = []
  9.         # large to small
  10.         # pop small
  11.         self.Heap2 = []

  12.     def addNum(self, num):
  13.         """
  14.         :type num: int
  15.         :rtype: None
  16.         """
  17.         heappush(self.Heap1, -num)
  18.         heappush(self.Heap2, -heappop(self.Heap1))
  19.         
  20.         if len(self.Heap2) > len(self.Heap1):
  21.             heappush(self.Heap1, -heappop(self.Heap2))

  22.     def findMedian(self):
  23.         """
  24.         :rtype: float
  25.         """
  26.         if len(self.Heap1) != len(self.Heap2):
  27.             return -self.Heap1[0]
  28.         else:
  29.             return (self.Heap2[0]-self.Heap1[0]) / 2


  30. # Your MedianFinder object will be instantiated and called as such:
  31. # obj = MedianFinder()
  32. # obj.addNum(num)
  33. # param_2 = obj.findMedian()
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-7-16 13:37:06 | 只看该作者
全局:
611        Valid Triangle Number        Medium        5        Two Pointers

  1. class Solution:
  2.     def triangleNumber(self, nums: List[int]) -> int:
  3.         N = len(nums)
  4.         ans = 0
  5.         nums = sorted(nums)
  6.         
  7.         for p in range(2, len(nums)):
  8.             p1, p2 = 0, p-1
  9.             while p1 < p2:
  10.                 if (nums[p1] + nums[p2]) > nums[p]:
  11.                     ans += (p2-p1)
  12.                     p2 -= 1
  13.                 else:
  14.                     p1 += 1
  15.         return ans
  16.         
  17.         """
  18.         res = 0
  19.         N = len(nums)
  20.         for i in range(N):
  21.             for j in range(i+1, N):
  22.                 for k in range(j+1, N):
  23.                     tmpList = [nums[i], nums[j], nums[k]]
  24.                     tmpList = sorted(tmpList)
  25.                     #print(tmpList)
  26.                     if tmpList[2] < (tmpList[0] + tmpList[1]):
  27.                         res += 1
  28.         return res
  29.         """
  30.                     
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-8-18 10:53:51 | 只看该作者
全局:
1448        Count Good Nodes in Binary Tree        Medium                DFS

回复

使用道具 举报

🔗
 楼主| Myron2017 2021-8-19 14:33:34 | 只看该作者
全局:
91        Decode Ways        Medium        5        DP

huahua 的解答很经典!
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-8-25 00:49:54 | 只看该作者
全局:
LC 537 Complex Number Multiplication

回复

使用道具 举报

🔗
 楼主| Myron2017 2021-8-25 08:35:09 | 只看该作者
全局:
537        Complex Number Multiplication
36        Valid Sudoku
653        Two Sum IV - Input is a BST
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-9-29 14:00:11 | 只看该作者
全局:
922        Sort Array By Parity II        Easy
929        Unique Email Addresses        Easy
350        Intersection of Two Arrays II        Easy
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表