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

Leetcode刷题记录帖

🔗
 楼主| mintyc 2018-5-8 22:55:54 | 只看该作者
全局:
May 8th 2018 --- 1 Problem

## 274. H-Index (Medium)

Sort the array. Scan the array to find some entry that its value equals to the number of entries larger or equal to it.

Be careful of the numbers with same value.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-9 20:57:12 | 只看该作者
全局:
May 9th 2018 --- 1 Problem

## 273. Integer to English Words (Hard)

Interpret it bit by bit ...
Pay attention to special occasions like 11-19 or zero.

One very useful method here:
``` java
    String.join("-", ans);
```
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-10 22:07:49 | 只看该作者
全局:
May 10th 2018 --- 1 Problem

## 274. H-Index (Medium)

Sort the array. Scan the array to find some entry that its value equals to the number of entries larger or equal to it.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-11 22:56:57 | 只看该作者
全局:
May 11th 2018 --- 1 Problem

## 279. Perfect Squares (Medium)

Dynamic programming.

``` java
ans[k] = Math.min(ans[k], ans[k - j * j] + 1)
```
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-13 00:25:22 | 只看该作者
全局:
May 13th 2018 --- 1 Problem

## 284. Peeking Iterator (Medium)

When you do peek(), just do next(), but use a variable to store the value. Keep returning this value to peek() until next next() request appears.

### Faults:
1.**[CE]** Confused 'left' and 'flag'.

补充内容 (2018-5-13 00:26):
May 12th 2018
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-13 20:20:42 | 只看该作者
全局:
May 13th 2018 --- 4 Problems

## 832. Flipping an Image (Easy)

Swap an array.

## 833. Find And Replace in String (Medium)

The only problem is if you replace some substring and its length is not the same, it will effect other replacements after.

So we could do the replacments backwards, just sort the index in ascending order in advance.

## 834. Sum of Distances in Tree (Hard)

Firstly, calculate `size[r]` (the size of subtree which has r as the root) and `collect[r]` (sum the distance from each node to root r) through recursion from bottom to top. Notice that `collect[r] += collect[son] + size[son]`.

Then, we could calculate the answer `dist[]` by `size[]` and `collect[root]` (`collect[root] == dist[root]`). Here is one important conclusion (`son` is one child of `r`'s ):

``` java
dist[son] = dist[root] - size[son] + (N - size[son]);
dist[son] = dist[root] + N - 2 * size[son]; // they are the same
```

## 835. Image Overlap (Medium)

Damn question.

### Faults:
1. **[WA]** Mind the difference between sliding, translation and rotation.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-15 01:00:56 | 只看该作者
全局:
May 14th 2018 --- 1 Problem

## 287. Find the Duplicate Number (Medium)

Consider each number an linkedlist from the value of its index to the number. Then there will be several linkedlists point to the same node. In other words, we need to find a cycle in a linked list.

Then it is the same as #142.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-16 01:19:08 | 只看该作者
全局:
May 15th 2018 --- 1 Problem

## 299. Bulls and Cows (Medium)

Use one array to count characters.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-17 00:02:07 | 只看该作者
全局:
May 16th 2018 --- 1 Problem

## 282. Expression Add Operators (Hard)

### 1. Recursion with the record of last successive multiplys

Easier and clearer way.

### 2. Generate the whole and calculate by convert infix to postfix

One recursion to cut the nums, another recursion to generate operators.

Then use convert infix expression to postfix to calculate the value.

Compared with above solution, this one is quite complicated. I spent a lot of time on nearly 100 lines of code.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-17 19:53:17 | 只看该作者
全局:
May 17th 2018 --- 4 Problems

## 289. Game of Life (Medium)

The problem is we could not display the two status with one bit at the same time.

Then we could use two bits! Last bit for status at this turn, and first bit for status at next turn!

## 295. Find Median from Data Stream (Hard)

### 1. Two Priority Queue

Two priority queue, one for the left half and one for the right.
Maintain the capacity of each priority queue according to sum size.

### 2. Binary Search Tree

Always search for the middle one or two in the BST.

## 297. Serialize and Deserialize Binary Tree (Hard)

Convert the tree to preorder traversal, put "null" for null TreeNodes.

## 300. Longest Increasing Subsequence (Medium)

The classical optimization (nlog(n) by binary search) for longest increasing subsequence.

回复

使用道具 举报

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

本版积分规则

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