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

立贴!从今天开始刷题。

🔗
 楼主| ttgao 2019-5-10 12:06:52 | 只看该作者
全局:
Longest Palindromic Substring

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1:

Input: "babad"
Output: "bab"
Note: "aba" is also a valid answer.

Example 2:

Input: "cbbd"
Output: "bb"

回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-10 12:07:07 | 只看该作者
全局:
用DP实现的此题。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-10 13:10:41 | 只看该作者
全局:
Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.

Example 1:

Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.

Example 2:

Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.

Example 3:

Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
             Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-10 13:11:00 | 只看该作者
全局:
本来想用DP做,后来发现其实不用。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-12 11:58:06 | 只看该作者
全局:
139. Word Break

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

Note:

    The same word in the dictionary may be reused multiple times in the segmentation.
    You may assume the dictionary does not contain duplicate words.

Example 1:

Input: s = "leetcode", wordDict = ["leet", "code"]
Output: true
Explanation: Return true because "leetcode" can be segmented as "leet code".

Example 2:

Input: s = "applepenapple", wordDict = ["apple", "pen"]
Output: true
Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
             Note that you are allowed to reuse a dictionary word.

Example 3:

Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
Output: false

回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-12 12:00:57 | 只看该作者
全局:
这题要用DP做。

简单讲就是DP[i]是表示以i为切割点,左边是否可以满足条件。

那此题最终就是测试DP[s.length()]是否为true;

等于关键是if(dp[j]&&substring(j-i)是否在字典里面)
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-12 12:30:23 | 只看该作者
全局:
206. Reverse Linked List

Reverse a singly linked list.

Example:

Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL

Follow up:

A linked list can be reversed either iteratively or recursively. Could you implement both?
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-12 12:30:50 | 只看该作者
全局:
这题比较简单,取出一个node就并入到新的list里面。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-12 13:11:48 | 只看该作者
全局:
141. Linked List Cycle

Given a linked list, determine if it has a cycle in it.

To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.



Example 1:

Input: head = [3,2,0,-4], pos = 1
Output: true
Explanation: There is a cycle in the linked list, where tail connects to the second node.

Example 2:

Input: head = [1,2], pos = 0
Output: true
Explanation: There is a cycle in the linked list, where tail connects to the first node.

Example 3:

Input: head = [1], pos = -1
Output: false
Explanation: There is no cycle in the linked list.



Follow up:

Can you solve it using O(1) (i.e. constant) memory?
回复

使用道具 举报

🔗
开心宝宝 2019-5-13 02:04:18 | 只看该作者
本楼:
全局:
楼主加油
回复

使用道具 举报

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

本版积分规则

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