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

刷题记录帖子

🔗
 楼主| Myron2017 2021-9-30 08:00:48 | 只看该作者
全局:
725        Split Linked List in Parts        Medium
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-11-1 11:33:48 | 只看该作者
全局:
2059        Minimum Operations to Convert Number        Medium

BFS to solve minimum operations
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-11-1 11:34:14 | 只看该作者
全局:
2058, 2057 easy quetsions in this week's contest
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-11-25 08:15:51 | 只看该作者
全局:
986        Interval List Intersections        Medium        4        Disjoint and Sorted intervals
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-11-25 12:28:20 | 只看该作者
全局:
2078        Two Furthest Houses With Different Colors        Medium        4        Greedy Variant Using two anchor points
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-11-25 12:32:44 | 只看该作者
全局:
2079        Watering Plants        Medium        3        Simulation
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-11-25 12:35:28 | 只看该作者
全局:
2080        Range Frequency Queries        Medium        3        HashMap + Bisect
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-12-1 14:50:14 | 只看该作者
全局:
198        House Robber        Medium        4        DP
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-12-1 15:36:15 | 只看该作者
全局:
116        Populating Next Right Pointers in Each Node        Medium        3        Level Order Traversal
  1. class Solution:
  2.     def connect(self, root: 'Node') -> 'Node':
  3.         
  4.         if not root:
  5.             return root
  6.         
  7.         # Start with the root node. There are no next pointers
  8.         # that need to be set up on the first level
  9.         leftmost = root
  10.         
  11.         # Once we reach the final level, we are done
  12.         while leftmost.left:
  13.             
  14.             # Iterate the "linked list" starting from the head
  15.             # node and using the next pointers, establish the
  16.             # corresponding links for the next level
  17.             head = leftmost
  18.             while head:
  19.                
  20.                 # CONNECTION 1
  21.                 head.left.next = head.right
  22.                
  23.                 # CONNECTION 2
  24.                 if head.next:
  25.                     head.right.next = head.next.left
  26.                
  27.                 # Progress along the list (nodes on the current level)
  28.                 head = head.next
  29.             
  30.             # Move onto the next level
  31.             leftmost = leftmost.left
  32.         
  33.         return root
复制代码
回复

使用道具 举报

🔗
 楼主| Myron2017 2021-12-3 01:15:37 | 只看该作者
全局:
328        Odd Even Linked List        Medium        4
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. #     def __init__(self, val=0, next=None):
  4. #         self.val = val
  5. #         self.next = next
  6. class Solution:
  7.     def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:
  8.         if not head: return head
  9.         if not head.next: return head
  10.         
  11.         dummay1 = head
  12.         dummay2 = head.next
  13.         head_even = head.next
  14.         curr = head.next.next
  15.         
  16.         while curr:
  17.             # connect odd
  18.             dummay1.next = curr
  19.             dummay1 = curr
  20.             # coonect even
  21.             if curr.next:
  22.                 dummay2.next = curr.next
  23.                 dummay2 = curr.next
  24.                 curr = dummay2.next
  25.             else:
  26.                 # even not exist
  27.                 dummay2.next = None
  28.                 break
  29.             
  30.         # Connect odd to even
  31.         dummay1.next = head_even
  32.         return head
  33.         
  34.         
复制代码
回复

使用道具 举报

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

本版积分规则

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