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

打卡帖 告别拖延症~

🔗
 楼主| UCLA34 2021-2-13 09:21:00 | 只看该作者
全局:
92 days left
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-14 03:59:08 | 只看该作者
全局:
思想1: 前进/后退的符合条件的

比如:

image.png (22.4 KB, 下载次数: 1)

image.png
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-25 23:11:45 | 只看该作者
全局:
class Solution:
    def trimBST(self, root: TreeNode, low: int, high: int) -> TreeNode:
        
        def trim(node):
            if node is None:
                return None
            elif node.val > high:
                return trim(node.left)
            elif node.val < low:
                return trim(node.right)
            else:
                node.left = trim(node.left)
                node.right = trim(node.right)
               
                # what should i return here
                return node
            
        return trim(root)
               
Leetcode 669
递归:
一般binary search tree都是recursion
然后用subfunction的时候用node不用root
最后用root call一次这个function
还是要理解recursion的精髓。。
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-25 23:45:13 | 只看该作者
全局:
self tip: 要有耐心检查code,不要依靠run来检查
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-27 03:54:01 | 只看该作者
全局:
https://stackoverflow.com/questi ... -attributes/4233482

s = sorted(s, key = lambda x: (x[1], x[2]))
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-27 07:20:12 | 只看该作者
全局:
lintcode

    def hasCycle(self, head):
        # write your code here
        if head is None:
            return False

        fast = slow = head

        while fast != None:
            if fast.next is None:
                return False

            # there is a cycle since fast already catches up with slow
            if fast.next == slow:
                return True

            # we need to make sure fast.next is not None
            # so we will not get None.next
            fast =  fast.next.next
            slow = slow.next

        return False

Since we need to make sure fast.next is never None, if not , we will get into trouble like

"None.next"
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-29 00:08:00 | 只看该作者
全局:
python pointer problem
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-29 03:20:35 | 只看该作者
全局:
成功 reverse 一个 LinkedList
Lintcode 35
正反两个方法 都做一次
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-30 02:35:10 | 只看该作者
全局:
虽然没有什么好骄傲的,但是也算是一个里程碑,加油

image.png (11.1 KB, 下载次数: 0)

image.png
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-3-31 06:04:39 | 只看该作者
全局:
LinkedList  tips

if there is node.next.next:
always check node.next

same goes for node.next and node

回复

使用道具 举报

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

本版积分规则

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