自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(40)
  • 收藏
  • 关注

原创 [Leetcode]Add and Search Word - Data structure design

Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only letter

2015-08-31 17:06:00 272

原创 [Leetcode]House Robber II

Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time

2015-08-28 15:14:03 227

原创 [Leetcode]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 house

2015-08-28 13:54:57 211

原创 [Leetcode]Kth Largest Element in an Array

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.N

2015-08-27 15:37:54 238

原创 [Leetcode]Combination Sum III

Find all possible combinations of k numbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wit

2015-08-26 14:40:37 150

原创 [Leetcode]Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm should run

2015-08-26 13:01:33 218

原创 [Leetcode]Contains Duplicate III

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] andnums[j] is at most t and the difference between i and

2015-08-25 14:49:09 307

原创 [Leetcode]Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0R

2015-08-24 22:03:04 273

原创 [Leetcode]Count Complete Tree Nodes

Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled,

2015-08-23 15:14:15 281

原创 [Leetcode]Basic Calculator II

Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces. The integer division should

2015-08-23 10:50:58 318

原创 [Leetcode]Basic Calculator

Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty

2015-08-21 23:24:10 292

原创 [Leetcode]Majority Element II

Given an integer array of size n, find all elements that appear more than⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.class Solution {public: /*alorithm: hash solu

2015-08-21 10:58:16 150

原创 [Leetcode]Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find thekth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the BST

2015-08-20 22:20:59 276

原创 [Leetcode]Lowest Common Ancestor of a Binary Tree

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes

2015-08-20 12:54:58 235

原创 [Leetcode] Product of Array Except Self

Given an array of n integers where n > 1, nums, return an arrayoutput such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division and in O(n).

2015-08-19 11:34:22 214

原创 [Leetcode]Single Number III

Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums =

2015-08-18 17:27:45 234

原创 [Leetcode]Search a 2D Matrix II

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 in ascending from left to right.Integers in

2015-08-18 17:17:07 176

原创 [Leetcode]ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I

2015-08-18 14:00:29 197

原创 [Leetcode]Binary Tree Paths

Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]algorithm: dfs /*

2015-08-17 12:38:45 340

原创 [Leetcode]String to Integer (atoi)

Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input case

2015-08-14 16:32:26 186

原创 [Leetcode]Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution {public: /*algorithm if x is neg numer, and -x overlfows, return 0 ot

2015-08-12 22:24:13 167

原创 [Leetcode]Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.class Solution {public: /*algorithm for number abcd , compare head and tail digit meantime if it is same, rem

2015-08-12 21:46:32 174

原创 [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.class Solution {public:/*Symbol ValueI 1V 5X 10L 50C 100D 500M 1,000

2015-08-12 20:25:52 150

原创 [Leetcode]Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: /*algorithm loop from len = 0 to maxlen of strings each loop check wheh

2015-08-12 18:10:43 228

原创 [Leetcode]Remove Nth Node From End of List

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 end, the l

2015-08-12 17:35:52 176

原创 [Leetcode] Valid Parentheses

Given a string containing just the characters '(', ')','{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid b

2015-08-12 16:29:14 131

原创 [Leetcode]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 ListN

2015-08-12 14:15:44 158

原创 [Leetcode]Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you must do this in place with

2015-08-12 14:07:24 178

原创 [Leetcode] Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.class

2015-08-12 14:00:10 140

原创 [Leetcode]Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following

2015-08-12 11:15:36 184

原创 [Leetcode]Count and Say

The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one 2

2015-08-11 21:59:33 189

原创 [Leetcode]Add Binary

Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".class Solution {public: /*algorithm add it from the tail, plug carr

2015-08-11 20:59:39 182

原创 [Leetcode] Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?class Solution {p

2015-08-11 13:27:18 175

原创 [Leetcode]Excel Sheet Column Number

Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z

2015-08-08 22:01:00 194

原创 [Leetcode]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]. Note:Try to come up as many solutions as you ca

2015-08-08 20:59:40 208

原创 [Leetcode]Count Primes

Description:Count the number of prime numbers less than a non-negative number, n.class Solution {public: /*algorithm:brute force check [2-n]element one by one time: O(n2), spa

2015-08-08 13:31:30 209

原创 [Leetcode]Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].class Solution {public: string itos(int num){

2015-08-07 13:12:03 384

原创 [Leetcode]Implement Queue using Stacks

Implement Queue using StacksImplement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek()

2015-08-07 12:30:35 236

原创 [Leetcode]Palindrome Linked List

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?/**  * Definition for singly-linked list.  * struct ListNode {  *     int va

2015-08-06 16:56:22 225

原创 [Leetocde]Lowest Common Ancestor of a Binary Search Tree

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee

2015-08-06 15:37:13 285

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除