📣 独立日限时特惠: VIP通行证立减$68
楼主: mintyc
跳转到指定楼层
上一主题 下一主题
收起左侧

Leetcode刷题记录帖

🔗
 楼主| mintyc 2018-4-20 22:34:27 | 只看该作者
全局:
Apr. 20th 2018 --- 1 Problem

## 179. Largest Number (Medium)

### LCM (My solution)

Extend two strings to their lcm length then compare them.

### Connect

Compare (s1 + s2) with (s2 + s1).

### Faults:

1. **[WA]** Compare until one string ends is not enough.
2. **[WA]** The result maybe "00000..." but you should output "0" instead.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-4-21 21:24:50 | 只看该作者
全局:
Apr. 21st 2018 --- 4 Problems

## 184. Department Highest Salary (Medium)

    SELECT D.Name AS Department ,E.Name AS Employee ,E.Salary
    FROM
        Employee E,
        (SELECT DepartmentId,max(Salary) as max FROM Employee GROUP BY DepartmentId) T,
        Department D
    WHERE E.DepartmentId = T.DepartmentId
    AND E.Salary = T.max
    AND E.DepartmentId = D.id

## 185. Department Top Three Salaries (Hard)

    SELECT D.Name AS Department, E.Name AS Employee, E.Salary
    FROM Department D, Employee E, Employee E2  
    WHERE D.ID = E.DepartmentId AND E.DepartmentId = E2.DepartmentId AND
    E.Salary <= E2.Salary
    GROUP BY D.ID,E.Name HAVING COUNT(DISTINCT E2.Salary) <= 3
    ORDER BY D.Name, E.Salary DESC

## 187. Repeated DNA Sequences (Medium)

Store the string into hash tables. Both HashSet or HashMap is enough.

## 188. Best Time to Buy and Sell Stock IV (Hard)

e[k] means how much we can earn if we had k transactions and finished the lastest one on day i.

e[k] = max{max(e[j][k - 1]) - prices[l]} (j < l < i)

However the input K maybe meaningless large. So we need to firgure out whats the largest number of transactions we could have? The answer is (prices.length / 2). In such a condition, there in no consecutive increasing prices in the input.

### Faults:

1. **[TLE]** K too large.
2. **[TLE]** K too large.
3. **[TLE]** K too large.


回复

使用道具 举报

🔗
 楼主| mintyc 2018-4-23 00:03:36 | 只看该作者
全局:
本帖最后由 mintyc 于 2018-4-23 00:05 编辑

Apr. 22nd 2018 --- 4 Problems

## 820. Short Encoding of Words (Medium)

Arrays.sort()
String.endsWith(StringB)

## 821. Shortest Distance to a Character (Easy)

Scan forwards and backwards.

## 822. Card Flipping Game (Medium)

Problem description is crap.

Find the smallest number which doesn't appear on the front and back of the same card.

### Faults:

1. **[WA]** Crap description.
2. **[WA]** Crap description.

## 823. Binary Trees With Factors (Medium)

Dynamic programming.

wasy means the ways of binary trees with i-th (sorted) value as the root.

ways += ways[j] * ways[i / j];

回复

使用道具 举报

🔗
 楼主| mintyc 2018-4-23 21:52:15 | 只看该作者
全局:
Apr. 23rd 2018 --- 5 Problems

## 192. Word Frequency (Medium)

    cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{ print $2, $1 }'

https://leetcode.com/problems/wo ... My-simple-solution-(one-line-with-pipe)

## 194. Transpose File (Medium)

    awk '
    {
        for (i = 1; i <= NF; i++) {
            if(NR == 1) {
                s= $i;
            } else {
s = s " " $i;
            }
        }
    }
    END {
        for (i = 1; s != ""; i++) {
            print s;
        }
    }' file.txt

## 199. Binary Tree Right Side View (Medium)

Recursion.

Always keep updating because the node you visit later will always be on the right.

## 200. Number of Islands (Medium)

FloodFill.

## 201. Bitwise AND of Numbers Range (Medium)


    int offset = 0;
    while(m != n){
        m >>= 1;
        n >>= 1;
        offset++;
    }
    return m <<= offset;

### Faults:

1. **[TLE]**
2. **[TLE]**


回复

使用道具 举报

🔗
 楼主| mintyc 2018-4-24 21:50:03 | 只看该作者
全局:
Apr. 24th 2018 --- 3 Problems

## 207. Course Schedule (Medium)

First turn the input list of edges into Map from courses and List.

Then use topo sort with queue to proceed all courses. If the number of courses we polled out of queue equals to the number of courses, the answer is "true".

## 208. Implement Trie (Prefix Tree) (Medium)

Trie.

## 209. Minimum Size Subarray Sum (Medium)

Slide window.


回复

使用道具 举报

🔗
 楼主| mintyc 2018-4-25 22:01:54 | 只看该作者
全局:
Apr. 25th 2018 --- 3 Problems

## 210. Course Schedule II (Medium)

Same as #207.

### Faults:
1. **[CE]** Extra bracket.

## 211. Add and Search Word - Data structure design (Medium)

Same as #208.

## 212. Word Search II (Hard)

Search the trie while go through the board.
Break when there is no succeeding node in the trie.

### Faults:
1. **[WA]** Confusing DFS code.
1. **[WA]** Return before recover the array.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-4-26 22:21:08 | 只看该作者
全局:
Apr. 26th 2018 --- 2 Problems

## 213. House Robber II (Medium)

Same as #198. Do the same process for twice, once rob the first houst, once not.

## 214. Shortest Palindrome (Hard)

Match string s with its reverse r.

The length of matched string till the last char of t will be the part of palindrome we could make use of. Add the left part.

回复

使用道具 举报

🔗
水锦鲤 2018-4-27 01:24:27 | 只看该作者
全局:
follow lz的脚步!
回复

使用道具 举报

🔗
 楼主| mintyc 2018-4-27 21:43:21 | 只看该作者
全局:
Apr. 27th 2018 --- 1 Problem

## 215. Kth Largest Element in an Array (Medium)

### 1. QuickSort O(nlogn)
### 2. Heap O(nlogn)
### 3. QuickSelect O(n) https://en.wikipedia.org/wiki/Quickselect


回复

使用道具 举报

🔗
 楼主| mintyc 2018-4-27 21:43:50 | 只看该作者
全局:

谢谢 一起加油! 最近事情太多一天也刷不了几道题……
回复

使用道具 举报

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

本版积分规则

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