leetcode
文章平均质量分 77
yingzijk
小菜鸟!慢慢学习吧!加油!
展开
-
Sort Colors
【题目】Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the int转载 2016-06-20 17:27:52 · 440 阅读 · 0 评论 -
Remove Nth Node From End of List(easy)
【题目】 Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node fro原创 2016-06-01 18:00:15 · 243 阅读 · 0 评论 -
Swap Nodes in Pairs(easy)
【题目】Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constan转载 2016-06-01 17:37:11 · 266 阅读 · 0 评论 -
Implement strStr()
【题目】Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.【题意】 实现strstr(). 返回needle(关键字)在haystack(字符串)中第一次出现的原创 2016-05-09 17:13:58 · 290 阅读 · 0 评论 -
Copy List with Random Pointer
题:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.题意:copy一个链表(深拷贝),链表包含一个next指原创 2016-05-07 10:41:30 · 309 阅读 · 0 评论 -
Reverse Words in a String
题:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".题意:字符串反转(去除重复的空格)。分析:1,要求删除开头和结尾的多余空格。2,如果两个单词之间有多原创 2016-05-07 11:08:32 · 364 阅读 · 0 评论 -
Surrounded Regions
题:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O XX X O原创 2016-05-07 13:29:33 · 245 阅读 · 0 评论 -
Clone Graph
题目:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for转载 2016-05-07 14:09:44 · 262 阅读 · 0 评论 -
Candy
【题目】There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at原创 2016-05-07 14:20:49 · 345 阅读 · 0 评论 -
Trapping Rain Water
【题目】Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,原创 2016-05-08 09:24:45 · 275 阅读 · 0 评论 -
Scramble String
【题目】Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \转载 2016-05-08 10:45:02 · 390 阅读 · 0 评论 -
Simplify Path
【题目】Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:原创 2016-05-09 15:42:04 · 323 阅读 · 0 评论 -
Insertion Sort List(medium)
【题目】 Sort a linked list using insertion sort.【题意】 在链表中实现插入排序【分析】 传统数组版本做法就是两重循环,第一重是遍历所有元素,第二重是遍历已排序部分进行插入。对链表进行插入排序的正确方法是:新建一个头节点,遍历原来的链表,对原链表的每个节点找到新链表中适合插入位置的前指针,然后执行插入操作。原创 2016-06-01 16:53:53 · 272 阅读 · 0 评论 -
Same Tree
【题目】 Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same原创 2016-05-18 18:20:49 · 219 阅读 · 0 评论 -
Binary Tree Preorder Traversal
【题目】 Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \原创 2016-05-18 18:22:54 · 204 阅读 · 0 评论 -
Search a 2D Matrix(medium)
【题目】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 o原创 2016-06-02 09:46:33 · 245 阅读 · 0 评论 -
Search for a Range(medium)
【题目】 Given a sorted array of integers, 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 target is not原创 2016-06-02 10:09:31 · 303 阅读 · 0 评论 -
Binary Tree Inorder Traversal
【题目】 Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recurs原创 2016-05-20 09:35:31 · 261 阅读 · 0 评论 -
Word Search
【题目】 Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or ver原创 2016-06-20 09:30:40 · 484 阅读 · 0 评论 -
Two Sum(easy)
【题目】Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nu转载 2016-06-07 09:32:16 · 223 阅读 · 0 评论 -
Spiral Matrix(medium)
【题目】Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]原创 2016-06-06 15:27:44 · 256 阅读 · 0 评论 -
Merge Sorted Array(easy)
【题目】 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal tom + n)原创 2016-06-06 15:02:54 · 267 阅读 · 0 评论 -
Remove Element(easy)
【题目】 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 m原创 2016-06-06 09:29:42 · 221 阅读 · 0 评论 -
Construct Binary Tree from Inorder and Postorder Traversal(medium)
【题目】 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.【题意】 根据中序和后序遍历结果构原创 2016-05-23 10:35:52 · 254 阅读 · 0 评论 -
Construct Binary Tree from Preorder and Inorder Traversal (medium)
【题目】 Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.【题意】 根据先序遍历和中序遍历创建二叉树即转载 2016-05-23 10:24:14 · 356 阅读 · 0 评论 -
Search in Rotated Sorted Array(hard)
【题目】 Suppose a sorted array 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 found in the arra原创 2016-06-03 16:09:50 · 261 阅读 · 0 评论 -
Search Insert Position(medium)
【题目】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原创 2016-06-03 11:25:17 · 249 阅读 · 0 评论 -
3Sum (medium)
【题目】Given an array S of n integers, are there elementsa, b, c in S such that a + b +c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not c转载 2016-06-07 09:50:08 · 220 阅读 · 0 评论 -
Word Break(medium)
【题目】Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["l转载 2016-06-24 09:40:54 · 332 阅读 · 0 评论 -
Sqrt(x)
【题目】 Implement int sqrt(int x).Compute and return the square root of x.【题意】 实现x的平方根函数【分析】 二分搜索【实现】public class Solution { public int mySqrt(int x) { d原创 2016-06-02 16:32:10 · 5955 阅读 · 0 评论 -
Merge k Sorted Lists(hard)
【题目】 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.【题意】 归并k个有序列表【分析】【实现】转载 2016-05-31 15:39:31 · 298 阅读 · 0 评论 -
Binary Tree Postorder Traversal
【题目】 Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recu原创 2016-05-20 09:46:54 · 226 阅读 · 0 评论 -
Merge Two Sorted Lists(easy)
【题目】 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.【题意】 链接两个有序表即对两个有序列表进行合并【分析原创 2016-05-31 15:23:46 · 227 阅读 · 0 评论 -
Length of Last Word(easy)
【题目】 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 w原创 2016-05-17 18:23:08 · 233 阅读 · 0 评论 -
Permutation I
【题目】Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]【题意】原创 2016-05-12 08:51:14 · 279 阅读 · 0 评论 -
Next Permutation
【题目】Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest po原创 2016-05-13 08:30:27 · 277 阅读 · 0 评论 -
Binary Tree Level Order Traversal (easy)
【题目】Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 2原创 2016-05-26 10:22:24 · 231 阅读 · 0 评论 -
Binary Tree Zigzag Level Order Traversal(medium)
[题目]Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given b原创 2016-05-26 09:53:58 · 377 阅读 · 0 评论 -
Combination Sum II
题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the原创 2016-05-11 08:47:00 · 478 阅读 · 0 评论 -
Permutations II
【题目】 Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,原创 2016-05-12 10:44:38 · 255 阅读 · 0 评论