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

刷题打卡贴

全局:

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

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

x
sql 608 medium Tree Node
Used case when clause to fulfill different conditions.
errors: 1. after the first case when clause, only need to use when  rather than case when
2. for second condition, if u used the in clause, you have no need to filter the condition again if the first one and second have something in common, but if you used the not in clause, you have to clarify every filters or the comparison will be wrong in not in clause

sql 1164 medium  Product Price at a Given Date
Using union clause seems faster than using left join and ifnull clause

sql 626 medium Exchange Seats
one: use the same tables left join id - 1 and id + 1 , second use the case when .

上一篇:有人读UIUC online cs Master嘛组队
下一篇:圣诞组队刷题
推荐
 楼主| sly-- 2020-1-12 13:15:21 | 只看该作者
全局:
python 53. maximum subarray
for this question, I would like to use dynamic programming. We wanna find the global maximum, not the local one, so we need a variable to keep the value of the global maximum. And for all the values in the array, we can set that if the previous sum is negative, we will only keep the current value. Then we should keep variable prev and variable curr. We should set the initiate global maximum if float('-inf'), so if the value in array was negative, we could still get the curr value.
101. Symmetric Tree
For this question, we would know if this is a symmetric tree, the value of root should be equal and the left leaf of t1 should be as same as the right leaf of t2. Then the right leaf of t1 should be as well as the left leaf of t2.
1. two sum
For this question, we get to know it will have exactly one answer and numbers cannot be used twice.  We can use hash map to reduce the big o time. We can assume if the compensate number is in dic then we just return the compensate number's idx and the curr value's idx, if not we can add the curr val in the dic.
回复

使用道具 举报

推荐
 楼主| sly-- 2019-12-23 04:11:38 | 只看该作者
全局:
python 387. First Unique Character in a String
class Solution:
    def firstUniqChar(self, s: str) -> int:
        c = collections.Counter(s)
        for idx, ch in enumerate(s):
            if c[ch] == 1:
                return idx
        return -1

sql 184. Department Highest Salary
SELECT d.name as Department, e.name as Employee, Salary
FROM employee e join department d on e.departmentid = d.id
WHERE (departmentid, salary) in (SELECT departmentid, max(salary)
     FROM employee
     GROUP BY 1)
   177. Nth Highest Salary
回复

使用道具 举报

推荐
 楼主| sly-- 2019-12-9 08:11:17 | 只看该作者
全局:
sql :
612. median Shortest Distance in a Plane
just join the same table, but when using on filter we can specify that one table only join the larger other table's value in order to reduce duplicate and save time.

1174. median Immediate Food Delivery II
don't have to use in clause to keep the record right, cause when u use min(order_date), the customer_pref should be also be min.

1158. Market Analysis I
took too much time to figure out the count and sum. left join can set the order_date is null

python 136 easy
read question carefully. It mentioned every element appears twice except for one, so we can use pop, if it was not only twice, it won't work. And use try except to pop first and catch except.
math way is better. sum set of the list and then multiply with 2 , finally minus the sum all the elements in the list
回复

使用道具 举报

🔗
 楼主| sly-- 2019-12-8 07:59:31 | 只看该作者
全局:
algorithm 104. Maximum Depth of Binary Tree
used the recursive way to track left and right leaf, but I did not figure out the comparison and the wrong return. It is better to do the none value condition first.
回复

使用道具 举报

🔗
 楼主| sly-- 2019-12-10 04:48:21 | 只看该作者
全局:
python 412. Fizz Buzz
improve the solution. We can use the method like logitic regression cost function. 'Fizz'* (1 or 0)+ 'Buzz'*(1 or 0) or i, so that we can compact the space.

sql 1212 medium
When you join one table on different columns, u can use or to realize this application.
回复

使用道具 举报

🔗
 楼主| sly-- 2019-12-12 15:10:39 | 只看该作者
全局:
sql 585. Investments in 2016
brutal solution use two subquery filter the tiv_2015 and filter the lat,lon

602. Friend Requests II: Who Has the Most Friends
just add up the frequency of every id, so we can select requester id union all select accepterd id
回复

使用道具 举报

🔗
 楼主| sly-- 2019-12-12 15:40:03 | 只看该作者
全局:
python
237. Delete Node in a Linked List
first the question only give you the node you will delete, so you don't have the previous node. You can only assign the next node value to this node and omit the next one.

206. Reverse Linked List
the code is almost right, only the sequence which make the big different. When use equal to the linked list, I think they change together.
回复

使用道具 举报

🔗
 楼主| sly-- 2019-12-15 04:06:14 | 只看该作者
全局:
sql 1070. Product Sales Analysis III

1285. Find the Start and End Number of Continuous Ranges
if it was discrete, the start won't have a value just larger  than it and the end won't have a value just smaller than it

602. Friend Requests II: Who Has the Most Friends
should use union all so we can keep the duplicate records. and do not have to count each subquery just count the total id frequency.

283. Move Zeroes
use one pointer keep the index of which value is not equal to zero, then we can swap the values
回复

使用道具 举报

🔗
 楼主| sly-- 2019-12-17 05:55:55 | 只看该作者
全局:
sql 1149. Article Views II
just need to query the people who see more than one article and then sort, don't have to figure out the most for each day.

1205. Monthly Transactions II
append the chargeback table under the transactions. There is a trick, cause we only use case when to judge two types, so we should filter out the state we won't use.
回复

使用道具 举报

🔗
 楼主| sly-- 2019-12-18 14:30:18 | 只看该作者
全局:
sql 580. Count Student Number in Departments
always miss one point in the question.

550. Game Play Analysis IV
did not go through the idea, so spent a lot of time working on this question.
回复

使用道具 举报

🔗
 楼主| sly-- 2019-12-19 05:09:36 | 只看该作者
全局:
sql 1098. Unpopular Books
not adept。
1107. New Users Daily Count
not clear with the datediff function, so datediff function should include the value in the question if it said at most 90.
回复

使用道具 举报

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

本版积分规则

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