一个多月几乎每天都有在leetcode上刷database和algorithms(偶尔因为final没刷)。下面是刷题记录:
6.1: db 6道: Shortest Distance in a Plane, Investments in 2016, Count Student Number in Departments, Get Highest Answer Rate Question, Winning Candidate, Managers with at Least 5 Direct Reports
6.2: algo 2道: House Robber, Best Time to Buy and Sell Stock
db 3道: Human Traffic of Stadium, Trips and Users, Department Top Three Salaries, Number of Transactions per Visit
6.3: db 4道: Market Analysis II, Students Report By Geography, Find Cumulative Salary of an Employee, Report Contiguous Dates
6.5: algo 3道: Maximum Subarray, Range Sum Query - Immutable, House Robber II
db 4道: User Purchase Platform, Find the Quiet Students in All Exams, Median Employee Salary, Total Sales Amount by Year
6.7: db 5道: Get the Second Most Recent Activity, Tournament Winners, Game Play Analysis V, Average Salary: Departments VS Company, Find Median Given Frequency of Numbers
algo 3道: Coin Change, Maximum Product Subarray,Longest Increasing Subsequence
6.8 db 6道: Calculate Salaries, Combine Two Tables, Delete Duplicate Emails, Customers Who Never Order, Employees Earning More Than Their Managers, Second Highest Salary
algo 1道: Longest Palindromic Substring,
6.11 algo 4道: Palindromic Substrings, Number of Longest Increasing Subsequence, Partition Equal Subset Sum, Partition to K Equal Sum Subsets
6.12 algo 1道: Best Time to Buy and Sell Stock with Cooldown 试了两三种解法
6.13 algo 5道: Middle of the Linked List, Palindrome Linked List, Remove Linked List Elements, Remove Duplicates from Sorted List, Linked List Cycle II
6.14 algo 4道: Add Two Numbers, Remove Nth Node From End of List, Sort List, Reorder List
6.16 algo 3道: Clone Graph, Number of Islands, Graph Valid Tree
6.17 algo 3道: Graph Valid Tree, Number of Connected Components in an Undirected Graph, Reverse Linked List
db 2道: New Users Daily Count, Project Employees III,
6.18 algo 5道: Reverse Linked List II, Rotate List, Swap Nodes in Pairs, Odd Even Linked List, Reverse Nodes in k-Group
db 8道: Product Sales Analysis III, Shortest Distance in a Plane, Investments in 2016, Count Student Number in Departments, Get Highest Answer Rate Question, Winning Candidate, Department Top Three Salaries, Trips and Users
6.19 algo 4道: Find K Pairs with Smallest Sums, Merge k Sorted Lists, Merge Two Sorted Lists, Kth Smallest Element in a Sorted Matrix
db 6道: Human Traffic of Stadium, Number of Transactions per Visit, Median Employee Salary, Find Cumulative Salary of an Employee, User Purchase Platform, Market Analysis II
6.20 algo 2道: Smallest Range Covering Elements from K Lists, Meeting Rooms,
db 5道: Report Contiguous Dates, Students Report By Geography, Find the Quiet Students in All Exams, Sales by Day of the Week, Total Sales Amount by Year
6.21 db 6道: Average Salary: Departments VS Company, Get the Second Most Recent Activity, Tournament Winners, Game Play Analysis V, Find Median Given Frequency of Numbers, Group Sold Products By The Date
algo 6道: Non-overlapping Intervals, Meeting Rooms II, Task Scheduler, Minimum Number of Arrows to Burst Balloons, Insert Interval, Employee Free Time
6.22 algo 6道: Binary Search, Longest Palindromic Subsequence, Gas Station, Find Smallest Letter Greater Than Target, Peak Index in a Mountain Array, Find Minimum in Rotated Sorted Array
db 2道: Trips and Users, Exchange Seats
6.23 algo 3道: Find Peak Element, Search in Rotated Sorted Array, Search in Rotated Sorted Array II
6.24 algo 4道: Search a 2D Matrix, Search a 2D Matrix II, Find K Closest Elements, Count of Range Sum
6.26 algo 4道: Minimum Size Subarray Sum, Fruit Into Baskets, Permutation in String, Longest Repeating Character Replacement
Tips:
1. For graph problems, need to get familiar with the algorithm under hood: e.g., LC 332;
2. For coordinates manipulation, a Map/Dict could make codes shorter; for duplicate check, use Set: e.g., LC 1496;
3. Fixed sum of pairs, consider Two sum: e.g., LC 1497.
2. Leetcode:
1179
reformat department table;
Select ID,
SUM(IF(MONTH = 'JAN', REVENUE, NULL)) AS JAN_REVENUE;
...
SUM(IF(MONTH = 'DEC', REVENUE, NULL)) AS DEC_REVENUE;
From
Department(table name)
Group By
ID
3.Leetcode:
617 Merge Two Binary Tree
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.
You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.