• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅

随笔分类 -  Leetcode

上一页 1 ··· 25 26 27 28 29 30 31 32 下一页
Leetcode: Partition List

摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the o... 阅读全文
posted @ 2014-06-24 23:11 neverlandly 阅读(500) 评论(0) 推荐(0)
Leetcode: Rotate List

摘要:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->... 阅读全文
posted @ 2014-06-23 23:28 neverlandly 阅读(255) 评论(0) 推荐(0)
Leetcode: Divide Two Integers

摘要:Best method(跟discuss vote最高相似):只有一种情况整数除以整数会overflow,那就是Integer.MIN_VALUE除以-1,这种情况特殊分析。 之所以要用long a, b代替dividend和divisor是因为:比如Integer.MAX_VALUE除以1,第21 阅读全文
posted @ 2014-06-21 06:31 neverlandly 阅读(369) 评论(0) 推荐(0)
Leetcode: Linked List Cycle II

摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?一次... 阅读全文
posted @ 2014-06-20 08:04 neverlandly 阅读(240) 评论(0) 推荐(0)
Leetcode: Single Number II

摘要:Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime co... 阅读全文
posted @ 2014-06-20 07:49 neverlandly 阅读(269) 评论(0) 推荐(0)
Leetcode: Linked List Cycle

摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Analysis: typical Runner Technique. 一次过 1 ... 阅读全文
posted @ 2014-06-20 07:14 neverlandly 阅读(243) 评论(0) 推荐(0)
Leetcode: Binary Tree Preorder Traversal

摘要:Analysis: 第一反应肯定是recursion(递归), 非常直接,但是题目要求不能用递归。如果要使用迭代的方法来写preorder traversal,最大的问题是要如何确定遍历节点的顺序,因为树的pre-order traversal其实很类似图的DFS,DFS可以用Stack来写,所以这 阅读全文
posted @ 2014-06-19 12:54 neverlandly 阅读(440) 评论(0) 推荐(0)
Leetcode: Single Number

摘要:Analysis: 需求里面要求O(N)时间以及无额外空间,这就排除了使用boolean array, hashmap这些个方法,只能在原数组上进行查找。O(N)基本上就相当于遍历数组. 最好的方法: 第二遍做法: 17行 & 运算符优先等级低于 == 所以一定要打括号 一样的思路另一个做法: 另外 阅读全文
posted @ 2014-06-19 06:37 neverlandly 阅读(316) 评论(0) 推荐(0)
Leetcode: Combination Sum

摘要:典型的recursion方法,找符合要求的path,存入result的ArrayList中。所以方法还是建立一个ArrayList<ArrayList<Integer>> result, 建立一个ArrayList<Integer> path,用recursion当找到符合条件的path时,存入re 阅读全文
posted @ 2014-06-19 05:57 neverlandly 阅读(378) 评论(0) 推荐(0)
Leetcode: Rotate Image

摘要:抠细节的题,题目思想如下:to implement the rotation in layers, if size is n, so there will be (int)(n / 2) layers that should be rotated. 需要注意的是:在下面这段code里面,需要注意的是 阅读全文
posted @ 2014-06-18 12:05 neverlandly 阅读(439) 评论(0) 推荐(0)
Leetcode: Longest Palindromic Substring && Summary: Palindrome

摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Example 2: Analysis: 想到 阅读全文
posted @ 2014-06-17 12:07 neverlandly 阅读(592) 评论(0) 推荐(0)
Leetcode: Reverse Nodes in k-Group

摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then le... 阅读全文
posted @ 2014-06-17 04:58 neverlandly 阅读(499) 评论(0) 推荐(0)
Leetcode: Substring with Concatenation of All Words

摘要:You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatena... 阅读全文
posted @ 2014-06-14 00:40 neverlandly 阅读(340) 评论(0) 推荐(0)
Leetcode: Merge k Sorted List

摘要:参看别人的思路,类似MergeSort的思路,思路是先分成两个子任务,然后递归求子任务,最后回溯回来。这个题目也是这样,先把k个list分成两半,然后继续划分,直到剩下两个list就合并起来,合并时会用到Merge Two Sorted Lists这道题。 MergeSort的方法:我们来分析一下上 阅读全文
posted @ 2014-06-12 12:53 neverlandly 阅读(445) 评论(0) 推荐(0)
Leetcode: Generate Parentheses

摘要:又是把所有满足条件的结果存到一个ArrayList里面, 之前也有类似的如Letter combination of a Phone Number这道题。这种类型的题其实形成了一个套路,套路就是,recursion参数包括最终结果的集合(ArrayList),input(String),递归层次le 阅读全文
posted @ 2014-06-12 01:55 neverlandly 阅读(428) 评论(0) 推荐(0)
Leetcode: Longest Substring Without Repeating Characters

摘要:Use HashSet Use HashMap 阅读全文
posted @ 2014-06-11 03:24 neverlandly 阅读(358) 评论(0) 推荐(0)
Leetcode: ZigZag Conversion

摘要:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font ... 阅读全文
posted @ 2014-06-11 03:12 neverlandly 阅读(295) 评论(0) 推荐(0)
Leetcode: Letter Combinations of a Phone Number

摘要:像这种DFS的题目,常见的写法无外乎两种,使用recursion, 或者用Stack。本文采用了Recursion的方式。做完后积累的经验有:像这种在一个ArrayList里面罗列可能的path的题目,recursion的参数一般包括:包含最终结果的集合(ArrayList),input(Strin 阅读全文
posted @ 2014-06-11 02:24 neverlandly 阅读(672) 评论(0) 推荐(0)
Leetcode: Integer to Roman

摘要:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.一次过 1 public class Solution { 2 public S... 阅读全文
posted @ 2014-06-10 13:07 neverlandly 阅读(337) 评论(0) 推荐(0)
Leetcode: Container With Most Water

摘要:这道题我考虑过类似Trapping most water的做法,不大一样。那道题寻找左右最大元素,我可以确定那就是最优解,但是在这里,即使寻到了左右最大元素,我也不敢确定那是最优解。 然后我有考虑了DP全局最优&局部最优的做法,发现局部最优的递推式很难写。所以没有法了,网上看到说这道题用夹逼方法 T 阅读全文
posted @ 2014-06-10 13:06 neverlandly 阅读(295) 评论(0) 推荐(0)

上一页 1 ··· 25 26 27 28 29 30 31 32 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3