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

Leetcode刷题记录帖

🔗
 楼主| mintyc 2018-5-18 23:19:25 | 只看该作者
全局:
May 18th 2018 --- 1 Problem

## 304. Range Sum Query 2D - Immutable (Medium)

Including excluding principle.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-19 12:49:28 | 只看该作者
全局:
May 19th 2018 --- 1 Problem

## 309. Best Time to Buy and Sell Stock with Cooldown (Medium)

``` java
for (int i = 0; i < prices.length; i ++) {
    int tmpCool = Math.max(cool, sell);
    sell = buy + prices[i];
    buy = Math.max(cool - prices[i], buy);
    cool = tmpCool;
}
```
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-20 23:51:46 | 只看该作者
全局:
May 20th 2018 --- 1 Problem

## 307. Range Sum Query - Mutable (Medium)

Binary indexed tree.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-21 23:20:49 | 只看该作者
全局:
May 21st 2018 --- 1 Problem

## 301. Remove Invalid Parentheses (Hard)

Dynamic programming.

A valid string could be made up by two ways:
1. (string)
2. or  stringa + stringb

Then use DP or DFS based on these two rules.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-22 23:11:20 | 只看该作者
全局:
May 22nd 2018 --- 1 Problem

## 306. Additive Number (Medium)

These methods are all very useful here:

```java
last = Long.parseLong(sa);
next = Long.parseLong(sb);

String tmps = Long.valueOf(tmp).toString();

if (!num.substring(base, num.length()).startsWith(tmps))
    break;
```

### Faults:
1. **[RE]** Input maybe larger than integer.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-24 12:51:00 | 只看该作者
全局:
May 23rd 2018 --- 1 Problem

## 310. Minimum Height Trees (Medium)

For every node, to calculate its depth, there are two depths to compare with: the bottom-up depth of its deepest son, or the top-down depth from its father. The top-down depth of its father may come from two ways: its own father, or another child.

Here is own solution:

1. One DFS, calculate all bottom-up depth, record the deepest child and second deepest child for each node.
2. Another DFS, calculate the top-down depth for each node and get the final depth. For each node, compare its top-down depth and bottom-up depth. And we need to pass its top-down depth to its children: the top-down depth of its own, or the depth of its son's brother. We recorded the two deepest children for each node, so the brother's depth will always be avaliable.

Finally, find the nodes with shallowest depth.
回复

使用道具 举报

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

## 312. Burst Balloons (Hard)

Dynamic programming.

f[a][b] means all the balloons between a and b are burst. The last balloon be burst would be any balloon c between a and b. So we have:

```java
f[a][b] = Math.max(f[a][c] + f[c][b] + nums[a] * nums[c] * nums[b]);
```
nums[-1] and nums[n] would be helpful, add them in!
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-25 20:43:31 | 只看该作者
全局:
May 25th 2018 --- 1 Problem

## 313. Super Ugly Number (Medium)

The same as #264 but we got k primes here other than 3 primes. So instead of compare them by hand, we will use a priority queue to maintain the minimum next answer. Be careful will the duplicates.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-27 00:14:19 | 只看该作者
全局:
May 26th 2018 --- 2 Problems

## 315. Count of Smaller Numbers After Self (Hard)

Sort numbers by them value and build binary indexed tree on there original index.

## 316. Remove Duplicate Letters (Hard)

Scan backwards. If every character already appeared at least once starts from position P, then any position before P is avaliable for an answer. So try to find the smallest character before P to get the best answer. After fix the position of this character, call the solve function again to fix the other ones.
回复

使用道具 举报

🔗
 楼主| mintyc 2018-5-27 23:18:56 | 只看该作者
全局:
May 27th 2018 --- 4 Problems

## 840. Magic Squares In Grid (Easy)

Scan.

### Faults:
1. **[WA]** Input maybe larger than 9.
2. **[WA]** Input maybe smaller than 1.

## 841. Keys and Rooms (Medium)

BFS.

## 842. Split Array into Fibonacci Sequence (Medium)

Same as #306.

### Faults:
1. **[RE]** Input maybe larger than long.

## 843. Guess the Word (Hard)

Record all the tries and randomize.
回复

使用道具 举报

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

本版积分规则

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