LeetCode
havedream_one
这个作者很懒,什么都没留下…
展开
-
Binary Tree Postorder Traversal
Binary Tree Postorder TraversalGiven a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3},原创 2015-01-04 08:34:38 · 3692 阅读 · 0 评论 -
Binary Search Tree Iterator
Binary Search Tree Iterator原创 2015-01-06 09:04:47 · 3858 阅读 · 0 评论 -
Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321原创 2015-03-15 08:05:59 · 3998 阅读 · 0 评论 -
Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.原创 2015-03-19 08:39:00 · 3914 阅读 · 0 评论 -
Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].原创 2015-03-16 08:19:12 · 3885 阅读 · 0 评论 -
Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000原创 2015-03-12 07:40:27 · 3855 阅读 · 0 评论 -
Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2015-03-12 09:19:06 · 3845 阅读 · 0 评论 -
Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.原创 2015-03-18 08:10:12 · 3868 阅读 · 0 评论 -
Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative posit原创 2015-04-02 12:54:56 · 3704 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array II
Find Minimum in Rotated Sorted Array II原创 2015-01-06 08:42:24 · 3868 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array
Find Minimum in Rotated Sorted Array原创 2015-01-06 08:31:19 · 3672 阅读 · 0 评论 -
Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2015-01-05 15:56:06 · 3818 阅读 · 0 评论 -
Single Number
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 using ext原创 2015-01-04 16:11:36 · 3683 阅读 · 0 评论 -
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?/** * Definition for singly-linked list. *原创 2015-01-04 15:19:25 · 3658 阅读 · 0 评论 -
LRU Cache
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 the key if原创 2015-01-03 20:33:30 · 3735 阅读 · 0 评论 -
Binary Tree Preorder Traversal
Binary Tree Preorder TraversalGiven a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3},原创 2015-01-04 09:22:06 · 3740 阅读 · 0 评论 -
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?/** * Definition for singly-linked list. * class ListNode { * int val; *原创 2015-01-04 14:26:10 · 3671 阅读 · 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.原创 2015-01-04 20:50:22 · 3799 阅读 · 0 评论 -
Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t原创 2015-01-04 11:24:25 · 3704 阅读 · 0 评论 -
Candy
CandyThere are N children standing in a line. Each child is assigned a rating value.原创 2015-01-05 13:12:25 · 3675 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.原创 2015-04-03 13:54:43 · 3786 阅读 · 0 评论 -
Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked ListGiven a binary tree, flatten it to a linked list in-place.原创 2015-04-06 20:43:51 · 3775 阅读 · 0 评论 -
Count Primes
Description:Count the number of prime numbers less than a non-negative number, nReferences:How Many Primes Are There?Sieve of Eratosthenes题意很简单,求n以内的素数的个数注意:不包括n如果注意到refe原创 2015-05-03 08:54:14 · 1093 阅读 · 0 评论 -
LeetCode N-Queens
n 皇后问题原创 2015-07-31 19:30:50 · 406 阅读 · 0 评论 -
LeetCode----ZigZag Conversion
leetcode 6 ZigZag Conversion原创 2015-07-31 15:07:47 · 706 阅读 · 0 评论 -
LeetCode208 --- Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.原创 2015-07-22 18:32:50 · 796 阅读 · 0 评论 -
LeetCode -- Course Schedule
Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n - 1.原创 2015-07-22 15:46:07 · 628 阅读 · 0 评论 -
LeetCode 环形链表 II 以及 链表是否有环 详解原理
给定一个链表,返回链表开始入环的第一个节点。如果链表无环,则返回null。为了表示给定链表中的环,我们使用整数pos来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果pos是-1,则在该链表中没有环。说明:不允许修改给定的链表。设:起点为A,第一个入环的点为B;设有两个人,其中slower的速度是1,faster的速度为2,相遇点为C,环长度为L = L'...原创 2019-03-09 14:54:05 · 313 阅读 · 0 评论 -
java 队列方法详解
一、队列支持的方法(Queue) throw exception return special value insert add 1、增加元素不能为null 2、其他异常,比如有界队列 offer 1、元素不能为null 2、实现内部调用addF...原创 2019-03-09 20:55:59 · 6455 阅读 · 1 评论 -
LeetCode 搜索旋转排序数组
假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组[0,1,2,4,5,6,7]可能变为[4,5,6,7,0,1,2])。搜索一个给定的目标值,如果数组中存在这个目标值,则返回它的索引,否则返回-1。你可以假设数组中不存在重复的元素。你的算法时间复杂度必须是O(logn) 级别。示例 1:输入: nums = [4,5,6,7,0,1,...原创 2019-03-16 20:54:31 · 197 阅读 · 0 评论 -
LeetCode OJ 205 Isomorphic Strings
Given two strings s andt, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anoth原创 2015-05-03 13:49:11 · 1083 阅读 · 0 评论 -
88 Merge Sorted Array
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 to m + n) to hold ad原创 2015-05-10 18:21:45 · 933 阅读 · 0 评论 -
206 Reverse Linked List
Reverse a singly linked list. 总体思路是很简单的,按照将元素插入到链头的思路进行/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; }原创 2015-05-10 14:32:51 · 1193 阅读 · 0 评论 -
Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mostk transactions.Note:You may not原创 2015-04-06 19:45:28 · 4003 阅读 · 0 评论 -
Binary Tree Right Side View
Binary Tree Right Side ViewGiven a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.原创 2015-04-06 20:19:47 · 3857 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).原创 2015-04-07 10:35:06 · 3728 阅读 · 0 评论 -
House Robber
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 that adjacent houses have security system connected and it will automatical原创 2015-04-07 15:44:55 · 3847 阅读 · 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 value.原创 2015-04-07 10:48:05 · 3864 阅读 · 0 评论 -
Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4题意:求[m,n]之间所有数的按位与初看之下,觉得太简单不过了,直接依次遍历public class Solution { public int rangeBitwiseAnd(int m,原创 2015-04-20 08:04:22 · 888 阅读 · 0 评论 -
Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.原创 2015-04-09 09:14:23 · 6427 阅读 · 0 评论