查看: 7280| 回复: 52
跳转到指定楼层
上一主题 下一主题
收起左侧

打卡帖 告别拖延症~

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
每日总结

上一篇:weekly转码刷题打卡。给自己开个打卡贴
下一篇:求组队zoom刷题
推荐
 楼主| UCLA34 2021-1-26 01:30:30 | 只看该作者
全局:
1. python 的 super 模版 要加 super()
2. python read inline

class Person:
        def __init__(self, firstName, lastName, idNumber):
                self.firstName = firstName
                self.lastName = lastName
                self.idNumber = idNumber
        def printPerson(self):
                print("Name:", self.lastName + ",", self.firstName)
                print("ID:", self.idNumber)

class Student(Person):
    #   Class Constructor
    #   
    #   Parameters:
    #   firstName - A string denoting the Person's first name.
    #   lastName - A string denoting the Person's last name.
    #   id - An integer denoting the Person's ID number.
    #   scores - An array of integers denoting the Person's test scores.
    #
    # Write your constructor here
    def __init__(self, firstname, lastName, id, scores):
        super().__init__(firstName, lastName, id)
        self.scores = scores
   

    #   Function Name: calculate
    #   Return: A character denoting the grade.
    #
    # Write your function here
    def calculate(self):
        scores = self.scores
        if len(scores) == 0:
            return 'T'
        score = sum(scores) / len(scores)
        if 90 <= score <= 100:
            return 'O'
        if 80 <= score < 90:
            return 'E'
        if 70 <= score < 80:
            return 'A'
        if 55 <= score < 70:
            return 'P'
        if 40 <= score < 55:
            return 'D'
        if score < 40:
            return 'T'
        

line = input().split()
firstName = line[0]
lastName = line[1]
idNum = line[2]
numScores = int(input()) # not needed for Python
scores = list( map(int, input().split()) )
s = Student(firstName, lastName, idNum, scores)
s.printPerson()
print("Grade:", s.calculate())

line = input().split()
firstName = line[0]
lastName = line[1]
idNum = line[2]
scores = list(map(int, input().split()))
s = Student(firstName, lastName, idNum, scores)
s.printPerson
print("Grade: ", s.calculate())
回复

使用道具 举报

推荐
 楼主| 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-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-1-26 09:41:58 | 只看该作者
全局:
1: handling input and output
2: Set -> add   set([list])
3. queue -> append
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-1-29 12:55:10 | 只看该作者
全局:
    arr = list(map(int, input().rstrip().split()))
    arr = arr[::-1]
    arr = ' '.join(str(x) for x in arr)
    #print(' '.join(arr))
    print(arr)


    # .join() only joins strings list
    # you can do line 8 if you want to join integer list


    intervals = sorted(intervals, keys = lambda interval: interval.start)

    # this is template for lambda sort
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-2-3 22:24:52 | 只看该作者
全局:
今天小目标:模版总结完
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-2-4 01:01:35 | 只看该作者
全局:
dict, set, queue, list - 括号的问题 哪种括号,加在哪里
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-2-4 01:08:26 | 只看该作者
全局:
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-2-4 05:35:32 | 只看该作者
全局:
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-2-5 03:25:20 | 只看该作者
全局:
- [ ] strings/arrays
- [ ] sliding window
- [ ] prefix sums
- [ ] binary search
- [ ] heap
- [ ] trie
- [ ] dynamic programming
- [ ] topological sort
- [ ] tree traversal recursion
- [ ] bfs
- [ ] dfs
回复

使用道具 举报

🔗
 楼主| UCLA34 2021-2-5 06:48:58 | 只看该作者
全局:
del dict['item']

Toreview:
break continue
lambda, map, filter

list.remove(element)

pass in copy: original[:]

def example(self, animal = 'Dog', name = None, *toppings, **user_info)
# for default value and optional argument
# * toppings an arbitrary number of arguments
# ** user_info, an arbitrary number of keyword argument
# come in as dictionary
for key, value in user_info.items():
profile[key] = value

inheritance:

super().__init__(name)

b.sort(reverse = True) # sort a list
print(sorted(b)) # sort a list temporarily
b.reverse()
回复

使用道具 举报

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

本版积分规则

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