![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
peach_li
不牛不是我
展开
-
LeetCode- 238. Product of Array Except Self
Problem: Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without div原创 2016-05-17 20:55:22 · 855 阅读 · 0 评论 -
LeetCode--223. Rectangle Area
Problem:Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume t原创 2016-03-22 14:59:31 · 349 阅读 · 0 评论 -
LeetCode--242. Valid Anagram
Problem:Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may assume原创 2016-03-22 12:06:31 · 328 阅读 · 0 评论 -
LeetCode-5 Longest Palindromic Substring
Problem:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Subscr原创 2016-04-04 10:48:02 · 351 阅读 · 0 评论 -
LeetCode--181. Employees Earning More Than Their Managers
Problem: The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.+----+-------+--------+-----------+| Id | Name | Sala原创 2016-03-08 22:38:46 · 704 阅读 · 0 评论 -
LeetCode-Nim Game
Problem:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the la原创 2015-10-20 18:03:45 · 345 阅读 · 0 评论 -
LeetCode-Contains Duplicate III
Problem:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the dif原创 2015-10-10 23:16:50 · 413 阅读 · 0 评论 -
LeetCode-Contains Duplicate II
Problem:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis原创 2015-10-10 22:25:39 · 288 阅读 · 0 评论 -
LeetCode-Contains Duplicate 217
Problem:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false i原创 2015-10-10 21:42:20 · 314 阅读 · 0 评论 -
LeetCode-Invert Binary Tree
problem:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1analysis:利用递归将root的原创 2015-10-09 22:30:40 · 241 阅读 · 0 评论 -
LeetCode-Move Zeroes
Problem:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0,原创 2015-10-09 21:48:30 · 283 阅读 · 0 评论 -
LeetCode-Maximum Depth of Binary Tree
Problem:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.an原创 2015-10-08 23:10:30 · 269 阅读 · 0 评论 -
LeetCode-Add Digits
Problem:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1原创 2015-10-08 22:36:57 · 302 阅读 · 0 评论 -
LeetCode--329. Longest Increasing Path in a Matrix
Problem: Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to four directions: left, right,up or down. You may NOT move diagonally or mov原创 2016-03-04 22:16:37 · 323 阅读 · 0 评论 -
LeetCode--234. Palindrome Linked List
Problem: Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? Analysis:判断一个单向链表是否是回文链表,要求O(n)的时间复杂度和O(1)的空间复杂度。 算法有以下几种:遍历整个链原创 2016-03-05 21:34:54 · 378 阅读 · 0 评论 -
LeetCode-338. Counting Bits
Problem:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5原创 2016-04-04 11:59:27 · 376 阅读 · 0 评论 -
203. Remove Linked List Elements
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode remov原创 2016-03-23 16:01:01 · 262 阅读 · 0 评论 -
LeetCode--5. Longest Palindromic Substring
Problem: Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Analysis:原创 2016-05-06 11:36:01 · 791 阅读 · 0 评论 -
LeetCode--54. Spiral Matrix
Problem: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 ]]You原创 2016-05-04 11:12:03 · 545 阅读 · 0 评论 -
LeetCod-3. Longest Substring Without Repeating Characters
Problem:Given 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", wit原创 2016-05-03 10:49:40 · 377 阅读 · 0 评论 -
LeetCode-146. LRU Cache
Problem: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of原创 2016-04-15 10:37:15 · 728 阅读 · 0 评论 -
LeetCode-62. Unique Paths/63. Unique Paths II
Problem: 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 tr原创 2016-04-12 23:11:44 · 448 阅读 · 0 评论 -
LeetCode--299. Bulls and Cows
Problem:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a h原创 2016-03-23 10:10:09 · 275 阅读 · 0 评论 -
LeetCode-136. Single Number/137. Single Number II/260. Single Number III
Problem: 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原创 2016-04-06 18:42:43 · 331 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
Problem: Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice? For example, Given sorted array nums = [1,1,1,2,2,3], Your function should return length = 5, wit原创 2016-03-01 11:10:01 · 325 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
Problem: 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 thi原创 2016-03-01 10:19:17 · 258 阅读 · 0 评论 -
LeetCode-102,103,107,111总结
102. Binary Tree Level Order Traversal Problem: 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原创 2016-02-29 22:21:25 · 333 阅读 · 0 评论 -
LeetCode-198. House Robber
Problem: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is tha原创 2016-02-28 20:14:41 · 262 阅读 · 0 评论 -
LeetCode-290. Word Pattern
Problem:Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.Exa原创 2016-04-06 11:46:06 · 327 阅读 · 0 评论 -
LeetCode--24. Swap Nodes in Pairs
Problem: 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 const原创 2016-03-23 22:30:34 · 388 阅读 · 0 评论 -
LeetCode--14. Longest Common Prefix
Problem: Write a function to find the longest common prefix string amongst an array of strings.Answer: 算法1:逐个字符比较,时间复杂度为O(N*L),N是字符串个数,L是最长前缀的长度,运行时间3ms。public class Solution { public String lo原创 2016-03-23 17:59:07 · 335 阅读 · 0 评论 -
LeetCode--160. Intersection of Two Linked Lists
Problem: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists:A: a1 → a2 ↘原创 2016-03-06 15:33:22 · 289 阅读 · 0 评论 -
LeetCode--142. Linked List Cycle II
Problem: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up: Can you solve it without using extra原创 2016-03-06 11:51:38 · 248 阅读 · 0 评论 -
141. Linked List Cycle
Problem: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?Analysis: 利用快慢双指针,如果有环则快指针会追上慢指针,否则快指针先到达链表尾。 Answer:/** * Definition原创 2016-03-05 21:58:51 · 283 阅读 · 0 评论 -
LeetCode--Merge Two Sorted Lists
Problem: 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.Analysis: 题意:合并两个排序链表并返回一个新的列表。新列表应该由拼接在一原创 2015-11-27 10:45:05 · 250 阅读 · 0 评论 -
LeetCode--Happy Number
Problem: Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum o原创 2015-11-26 11:19:52 · 313 阅读 · 0 评论 -
LeetCode-Ugly Number
Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is no原创 2015-11-25 10:09:02 · 285 阅读 · 0 评论 -
LeetCode--Ugly Number II
Problem: Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence o原创 2015-11-25 10:38:43 · 311 阅读 · 0 评论 -
LeetCode-Climbing Stairs
Problem: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Subscribe to see which原创 2015-10-31 20:52:56 · 274 阅读 · 0 评论 -
Leetcode-Remove Duplicates from Sorted List
Problem: Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.Analysis:这个题很简单主要思想是原创 2015-10-30 20:48:39 · 262 阅读 · 0 评论