
LeetCode
chaoqunwz
互联网小白的学习之路...
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Flatten Binary Tree to Linked List leetcode java
题目: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like:原创 2017-08-15 20:47:44 · 237 阅读 · 0 评论 -
Divide Two Integers leetcode java
题目: Divide two integers without using multiplication, division and mod operator. public int divide(int dividend, int divisor) { if (dividend == 0 || divisor == 0) { return原创 2017-08-21 19:20:13 · 284 阅读 · 0 评论 -
N-Queens leetcode java
题目: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens原创 2017-08-21 18:51:30 · 218 阅读 · 0 评论 -
3Sum Closest leetcode java
题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would hav原创 2017-08-13 22:48:16 · 179 阅读 · 0 评论 -
4 Sum leetcode java
题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b+ c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note:原创 2017-08-13 22:32:15 · 279 阅读 · 0 评论 -
3 Sum leetcode java
题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a trip原创 2017-08-13 22:27:37 · 210 阅读 · 0 评论 -
Search in Rotated Sorted Array II leetcode java
题目: Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function to determine if a given target is原创 2017-08-13 21:41:56 · 164 阅读 · 0 评论 -
Search in Rotated Sorted Array leetcode java
题目: 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 array原创 2017-08-13 21:20:28 · 155 阅读 · 0 评论 -
Search a 2D Matrix leetcode java
题目: 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原创 2017-08-13 20:57:53 · 156 阅读 · 0 评论 -
Sqrt(int x) leetcode java
题目: Implement int sqrt(int x). Compute and return the square root of x. 题解: 这道题很巧妙的运用了二分查找法的特性,有序,查找pos(在这道题中pos=value),找到返回pos,找不到返回邻近值。 因为是求数x(x>=0) 的平方根, 因此,结果一定是小于等于x且大于等于原创 2017-08-13 20:46:49 · 296 阅读 · 0 评论 -
Single Number II leetcode java
题目: 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 complexity. Could you implement it with原创 2017-08-20 20:09:31 · 154 阅读 · 0 评论 -
Single Number leetcode java
题目: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without us原创 2017-08-20 20:02:03 · 178 阅读 · 0 评论 -
Longest Consecutive Sequence leetcode java
题目: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [原创 2017-08-20 19:44:20 · 167 阅读 · 0 评论 -
Surrounded Regions leetcode java
题目: 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 X X O原创 2017-08-20 19:26:24 · 179 阅读 · 0 评论 -
Evaluate Reverse Polish Notation leetcode java
题目: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2",原创 2017-08-20 19:14:55 · 173 阅读 · 0 评论 -
Simplify Path leetcode java
题目: Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" Corner Cases: Did you consider the原创 2017-08-20 18:44:42 · 196 阅读 · 0 评论 -
《leetCode》:Roman to integer
题目描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 基本字符 I V X L C D M 相应的阿拉伯数字表示为 1 5 10 50 100 500 1000 1、相同的数字连写、所表示的数等于这原创 2017-08-05 21:38:53 · 176 阅读 · 0 评论 -
Container With Most Water leetcode java
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). nvertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0原创 2017-08-21 20:10:59 · 227 阅读 · 0 评论 -
Median of Two Sorted Array leetcode java
题目: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 题解: 首先我们先明确原创 2017-08-14 19:47:09 · 164 阅读 · 0 评论 -
Swap Nodes in Pairs leetcode java
题目: 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.http://i.cnblogs.com/EditPosts.aspx?opt=1原创 2017-08-14 20:36:12 · 164 阅读 · 0 评论 -
Reverse Linked List II leetcode java
题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n sati原创 2017-08-15 20:14:53 · 220 阅读 · 0 评论 -
Remove Nth Node From End of List leetcode java
题目: 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 from the e原创 2017-08-14 21:24:04 · 180 阅读 · 0 评论 -
Partition List leetcode java
题目: 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 original relative order of the nodes in原创 2017-08-14 21:55:37 · 156 阅读 · 0 评论 -
Insertion Sort List Leetcode java
题目: Sort a linked list using insertion sort. 题解: Insertion Sort就是把一个一个元素往已排好序的list中插入的过程。 初始时,sorted list是空,把一个元素插入sorted list中。然后,在每一次插入过程中,都是找到最合适位置进行插入。 因为是链表的插入操作,需要维护pre,原创 2017-08-14 22:41:23 · 172 阅读 · 0 评论 -
Combinations
原题 Given two integers n and k, return all possible combinations of k numbers out of 1 … n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3],原创 2017-08-21 21:56:51 · 164 阅读 · 0 评论 -
Sort Colors leetcode java
原题 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原创 2017-08-21 21:22:57 · 211 阅读 · 0 评论 -
Longest Substring Without Repeating Characters leetcode java
题目: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is原创 2017-08-24 22:58:57 · 275 阅读 · 0 评论 -
Length of Last Word leetocde java
题目: 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 wo原创 2017-08-24 22:52:28 · 189 阅读 · 0 评论 -
Jump Game II leetcode java
题目: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your原创 2017-08-24 22:15:33 · 266 阅读 · 0 评论 -
Jump Game leetcode java
题目: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Dete原创 2017-08-24 21:58:17 · 210 阅读 · 0 评论 -
Longest Common Prefix leetcode java
题目: Write a function to find the longest common prefix string amongst an array of strings. 题解: 解题思路是,先对整个String数组预处理一下,求一个最小长度(最长前缀肯定不能大于最小长度)。 然后以第0个字符串作为参照,从第1个字符串到最后一个字符串,对同一位置做判断,原创 2017-08-24 16:01:05 · 214 阅读 · 0 评论 -
Linked List Cycle leetcode II java (寻找链表环的入口)
题目: 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? 题解: 这个连同I都是很经典的题啦,刷CC150原创 2017-08-14 21:03:35 · 179 阅读 · 0 评论 -
Linked List Cycle leetcode java (链表检测环)
题目: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 题解: 这道题连带着II是很经典的,在看CC150时候,纠结这个问题纠结了很久。在读了很多网上资料还有书的讲解以及和别人讨论之后,对这原创 2017-08-14 20:56:05 · 156 阅读 · 0 评论 -
Remove Duplicates from Sorted List II leetcode java
题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Give原创 2017-08-14 20:53:01 · 345 阅读 · 0 评论 -
Remove Duplicates from Sorted List leetcode java
题目: Given a sorted linked list, delete all duplicates such that each element appear onlyonce. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 题解: 这道题是经典原创 2017-08-14 20:43:47 · 169 阅读 · 0 评论 -
Merge Two Sorted Lists leetcode java
题目: 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. 题解: 这道题是链表操作题,题解方法很直观。 首先,进行边界条件判断原创 2017-08-14 20:41:24 · 240 阅读 · 1 评论 -
《leetCode》:Regular Expression Matching
题目描述: Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the enti原创 2017-08-05 21:27:57 · 205 阅读 · 0 评论 -
《leetCode》:palindrome Number
题目描述 Determine whether an integer is a palindrome. Do this without extra space. 题目大意:即检测一个数是否为回文数,不开辟额外的空间 public boolean isPalindrome(int x) { if (x<0 || (x!=0 && x%10==0)) return fa原创 2017-08-05 20:58:03 · 161 阅读 · 0 评论 -
Copy List with Random Pointer leetcode java
题目: 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. 题解: 如果要cop原创 2017-08-16 22:11:05 · 170 阅读 · 0 评论 -
Rotate List leetcode java
题目: 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. 题解: 这道题主要先理解题原创 2017-08-16 21:46:11 · 164 阅读 · 0 评论