📣 Back to School开学季 - VIP通行证5折优惠!蓝莓、Offer多多同步优惠
楼主: ttgao
跳转到指定楼层
上一主题 下一主题
收起左侧

立贴!从今天开始刷题。

🔗
 楼主| ttgao 2019-5-16 14:43:46 | 只看该作者
全局:
此题很有意思,用一个双向链表和hashmap来维护这个一个cache结构。很经典的题目。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-19 14:24:44 | 只看该作者
全局:
200. Number of Islands

Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

Example 1:

Input:
11110
11010
11000
00000

Output: 1

Example 2:

Input:
11000
11000
00100
00011

Output: 3
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-19 14:25:02 | 只看该作者
全局:
此题用DFS来解还是非常清晰的。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-19 14:27:45 | 只看该作者
全局:
23. Merge k Sorted Lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

Example:

Input:
[
  1->4->5,
  1->3->4,
  2->6
]
Output: 1->1->2->3->4->4->5->6

回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-19 14:34:11 | 只看该作者
全局:
此题据说要用PriorityQueue,我是不知道啥是PriorityQueue,看来要去学习一下。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-19 15:06:38 | 只看该作者
全局:
763. Partition Labels

A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.

Example 1:

Input: S = "ababcbacadefegdehijhklij"
Output: [9,7,8]
Explanation:
The partition is "ababcbaca", "defegde", "hijhklij".
This is a partition so that each letter appears in at most one part.
A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits S into less parts.

Note:

    S will have length in range [1, 500].
    S will consist of lowercase letters ('a' to 'z') only.
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-19 15:08:28 | 只看该作者
全局:
此题看到一个非常精彩的解法。先取出string里面的字符出现在string里面的最后一个位置。

然后从头到底遍历一边string如果范围扩大了就增加一下范围。然后等于的话正好切割完成。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-21 11:51:42 | 只看该作者
全局:
17. Letter Combinations of a Phone Number

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.

A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-21 11:52:04 | 只看该作者
全局:
这是一道DFS或者BFS的题目,感觉要好好掌握一下。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-21 12:16:41 | 只看该作者
全局:
89. Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit.

Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.

Example 1:

Input: 2
Output: [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2

For a given n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.

00 - 0
10 - 2
11 - 3
01 - 1

Example 2:

Input: 0
Output: [0]
Explanation: We define the gray code sequence to begin with 0.
             A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
             Therefore, for n = 0 the gray code sequence is [0].

回复

使用道具 举报

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

本版积分规则

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