leetcode
郭大侠写leetcode
这个作者很懒,什么都没留下…
展开
-
1007. 小黄车
Time Limit: 1sec Memory Limit:256MBDescription随着共享经济的兴起,大学城如今到处可见ofo小黄车. 小左现在打算每天都骑小黄车从宿舍去实验室. 假设大学城的地图可以简化为一个有向图,图中有N个地点(节点),用0到N-1进行编号,有些地点之间存在有向的道路(有向边). 小左的宿舍所在地点编号为0,实验室所在地点编号为N-1. 小左希原创 2017-06-20 11:11:35 · 1325 阅读 · 0 评论 -
27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.原创 2017-05-22 09:47:15 · 146 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2017-05-22 09:16:15 · 129 阅读 · 0 评论 -
25. 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.k is a positive integer and is less than or equal to the length of the linked list. If the nu原创 2017-05-21 18:31:47 · 177 阅读 · 0 评论 -
74. Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2017-06-05 20:29:36 · 195 阅读 · 0 评论 -
73. Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.将数组中零元素所在的行列置0public class Solution { public void setZeroes(int[][] matrix) { Set set1 =原创 2017-06-01 10:18:40 · 315 阅读 · 0 评论 -
71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"只需要设置对/.. /. 和 / 的判断即可public class Solution { pu原创 2017-06-01 09:50:51 · 168 阅读 · 0 评论 -
70. Climbing Stairs
Total Accepted: 170597Total Submissions: 432155Difficulty: EasyContributor: LeetCodeYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 st原创 2017-05-31 11:18:26 · 173 阅读 · 0 评论 -
69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.public class Solution { public int mySqrt(int x) { if (x == 0) return 0; int start = 1, end = x; w原创 2017-05-31 11:07:14 · 221 阅读 · 0 评论 -
67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".public class Solution { public String addBinary(String a, String b) {原创 2017-05-31 10:11:56 · 209 阅读 · 0 评论 -
28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.public class Solution { public int strStr(String haystack, Strin原创 2017-05-22 09:52:20 · 124 阅读 · 0 评论 -
35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2017-05-22 11:18:41 · 127 阅读 · 0 评论 -
34. Search for a Range
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the原创 2017-05-22 11:28:56 · 167 阅读 · 0 评论 -
1006. 单词变换
Time Limit: 1sec Memory Limit:256MBDescription对于两个只含有小写英文字母(’a’-‘z’)的单词word1和word2,你可以对word1进行以下3种操作: 1) 插入一个字母;2) 删除一个字母;3) 替换一个字母. 请计算将word1变换成word2的最少操作数. word1和word2的长度均原创 2017-06-20 11:09:49 · 1062 阅读 · 0 评论 -
1005. 最大和
Time Limit: 1sec Memory Limit:256MBDescription从数列A[0], A[1], A[2], ..., A[N-1]中选若干个数,要求相邻的数不能都选,也就是说如果选了A[i], 就不能选A[i-1]和A[i+1]. 求能选出的最大和. 1 请为下面的Solution类实现解决上述问题的函数maxSum,函数参数A是给原创 2017-06-19 15:12:49 · 527 阅读 · 0 评论 -
1004. 无环图
Description 在图论中,如果一个有向图从任意顶点出发无法经过若干条边回到该点,则这个图是一个有向无环图(Directed Acyclic Graph,DAG). 对于一个n个节点的有向图(节点编号从0到n-1),请判断其是否为有向无环图. 图的节点数和边数均不多于100000. 请为下面的Solution类实现解决上述问题的isDAG函数,函数参数中n为图的节原创 2017-06-19 14:44:06 · 545 阅读 · 0 评论 -
1003. 相连的1
Time Limit: 1sec Memory Limit:256MBDescription对于一个01矩阵A,求其中有多少片连成一片的1. 每个1可以和上下左右的1相连. 请为下面的Solution类实现解决这一问题的函数countConnectedOnes,函数参数A为给出的01矩阵,A的行数和列数均不大于1000. 函数的返回值是问题的答案. class原创 2017-06-19 14:27:32 · 435 阅读 · 0 评论 -
1001. 会议安排
Time Limit: 1sec Memory Limit:256MBDescriptionN个会议要同时举行,参会人数分别为A[0], A[1], ..., A[N-1]. 现有M个会议室,会议室可容纳人数分别为B[0], B[1], ..., B[M-1]. 当A[i] 1 请为下面的Solution类实现解决上述问题的函数assignConferenc原创 2017-06-19 14:22:36 · 463 阅读 · 0 评论 -
1002. 等价二叉树
Description两个二叉树结构相同,且对应结点的值相同,我们称这两个二叉树等价. 例如:以下两个二叉树等价 1 1 / \ / \ 2 3 2 3而以下两个则不等价 1 1 / \ / \原创 2017-06-19 14:10:13 · 366 阅读 · 0 评论 -
1000. 函数求值
Description定义超级和函数F如下:F(0, n) = n,对于所有的正整数n..F(k, n) = F(k – 1, 1) + F(k – 1, 2) + … + F(k – 1, n),对于所有的正整数k和n. 例1:F(1, 3) = 6 例2:F(2, 3) = 10 例3:F(10, 10) = 167960 题解:使用动态规原创 2017-06-19 13:12:37 · 247 阅读 · 0 评论 -
36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2017-05-22 13:04:08 · 172 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If foun原创 2017-05-22 12:51:19 · 172 阅读 · 0 评论 -
66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digi原创 2017-05-31 09:53:18 · 202 阅读 · 0 评论 -
64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2017-05-31 09:35:09 · 190 阅读 · 0 评论 -
20. Valid Parentheses
题目链接:https://leetcode.com/problems/valid-parentheses/#/descriptionDescriptionGiven a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid原创 2017-04-17 10:33:33 · 232 阅读 · 0 评论 -
12. Integer to Roman
题目链接:https://leetcode.com/problems/integer-to-roman/#/descriptionDescriptionGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.原创 2017-03-20 10:05:15 · 255 阅读 · 0 评论 -
11. Container With Most Water
题目链接:https://leetcode.com/problems/container-with-most-water/#/descriptionDescriptionGiven n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n ver原创 2017-03-19 21:38:45 · 323 阅读 · 0 评论 -
7. Reverse Integer
题目链接:https://leetcode.com/problems/reverse-integer/?tab=DescriptionDescriptionReverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Note:The input is assumed to be a 32-bit signed integer. Y原创 2017-02-24 20:44:11 · 299 阅读 · 0 评论 -
5. Longest Palindromic Substring
DescriptionGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example:Input: "cbbd"Output: "bb"原创 2017-02-24 17:11:03 · 226 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
DescriptionGiven a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the length of 1.Given "pwwkew", the answe原创 2017-02-23 21:25:32 · 206 阅读 · 0 评论 -
1. Two Sum
题目链接:https://leetcode.com/problems/two-sum/?tab=DescriptionDescriptionGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assum原创 2017-02-21 21:36:58 · 338 阅读 · 0 评论 -
2. Add Two Numbers
题目链接:https://leetcode.com/problems/add-two-numbers/?tab=DescriptionDescriptionYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse原创 2017-02-23 12:59:36 · 317 阅读 · 0 评论 -
9. Palindrome Number
题目链接:https://leetcode.com/problems/palindrome-number/?tab=DescriptionDescriptionDetermine whether an integer is a palindrome. Do this without extra space.Subscribe to see which compa原创 2017-02-27 20:51:22 · 294 阅读 · 0 评论 -
21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct Lis原创 2017-04-23 22:24:04 · 357 阅读 · 0 评论 -
23. Merge k Sorted Lists
题目Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题解将k个有序链表重新排序,这里涉及到k个链表的排序,可以使用有序队列解决。代码/** * Definition for singly-linked list.原创 2017-05-15 16:24:50 · 144 阅读 · 0 评论 -
22. Generate Parentheses
题目Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "原创 2017-05-15 15:46:14 · 172 阅读 · 0 评论 -
63. Unique Paths II
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2017-05-31 09:22:36 · 184 阅读 · 0 评论 -
62. Unique Paths(排列组合法&动态规划法)
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2017-05-31 00:14:19 · 538 阅读 · 0 评论 -
61. 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->NULL.代码/** * Definition for singly-原创 2017-05-30 22:13:14 · 133 阅读 · 0 评论 -
58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2017-05-30 21:39:26 · 193 阅读 · 0 评论