
leecode
立志做一个农民
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode word-break-ii
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, given s =“catsandd...原创 2019-05-04 20:55:11 · 107 阅读 · 0 评论 -
买卖股票的最佳利润
Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), ...原创 2019-05-08 10:43:13 · 130 阅读 · 0 评论 -
没有重复字符的最长子串
给定一个字符串,在不重复字符的情况下找出最长子字符串的长度。 例如,没有重复字母“abcabcbb”的最长子字符串是“abc”,长度为3。 对于“bbbbb”,最长的子字符串是“b”,长度为1。 用一个集合存放当前子串,循环遍历字符串中的字符 如果当前集合不包含当前字符,就将其加入集合。并对最长子串的最长长度进行更新 如果包含,就需要将该字符第一次出现的前面的所有字符从集合里删除。 直到循环结束...原创 2019-05-09 17:19:59 · 305 阅读 · 0 评论 -
longest-consecutive-sequence
给定一个未排序的整数数组,找出最长的连续元素序列的长度。 例如, 给定[100,4,200,1,3,2] 最长的连续元素序列是[1,2,3,4]。 返回其长度:4。 您的算法应该在O(n)复杂度下运行。 首先将数组的数据用hash表进行存放。这样查找每一个元素的时间复杂度就是O(1); 每次从数组中取出一个元素,然后在从该元素左右相邻元素在hash表中搜索。并记录该元素最长的相邻数目,并且将这些元...原创 2019-05-07 12:06:50 · 107 阅读 · 0 评论 -
链表系列操作总结
/** * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ 基本操作 查 查找第 m 个 结点 增 在末尾加入结点 public void addNode(ListNode head, int val) { ListNod...原创 2019-05-14 21:46:50 · 199 阅读 · 0 评论 -
Valid Parentheses
leetCode https://leetcode.com/problems/valid-parentheses/ 简单级别题目 Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. An input string ...原创 2019-05-07 20:03:39 · 168 阅读 · 0 评论 -
Swap Nodes in Pairs 交换链表中序列的顺序
给定一个链表,每两个相邻节点交换一次,并返回它的头部。 您不能修改列表节点中的值,只能修改节点本身。 例如: 给定1->2->3->4,您应该返回列表为2->1->4->3。 之前面试头条面试官就出了这道题,当时自己刷题还不足,对于链表的操作基本上还是很生疏,没能做出来,这还我第一次面试。 但是现在基本上还是能够摸索出一些链表中长用的一些方法: 1.双指针...原创 2019-05-11 10:26:10 · 191 阅读 · 0 评论