自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [leetcode] 329. Longest Increasing Path in a Matrix

题目: 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 move outside

2016-03-07 23:29:11 518

原创 [leetcode] 334. Increasing Triplet Subsequence

题目: Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should: Return true if there exists i, j, k such that arr[i] < arr[

2016-02-27 11:19:29 503

原创 [leetcode] 310. Minimum Height Trees

题目: For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called

2016-02-23 15:56:23 661

原创 [leetcode] 309. Best Time to Buy and Sell Stock with Cooldown

题目: 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 as many transactions as you like (ie, buy on

2016-02-22 11:40:30 2167 2

原创 [leetcode] 306. Additive Number

题目: Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the

2016-02-21 11:29:26 957

原创 [leetcode] 299. Bulls and Cows

题目: 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 hint

2016-02-21 11:13:20 383

原创 [leetcode] 304. Range Sum Query 2D - Immutable

题目: Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).Range Sum Query 2D The above rectangl

2016-02-18 15:34:41 339

原创 [leetcode] 301. Remove Invalid Parentheses

题目: Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and ).

2016-02-18 10:44:15 1280

原创 [leetcode] 300. Longest Increasing Subsequence

题目: Given an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], ther

2016-02-17 20:08:36 424

原创 [leetcode] 295. Find Median from Data Stream

题目:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median i

2016-02-04 10:26:38 506

原创 [leetcode] 292.Nim Game

题目: 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 last stone will be

2015-10-14 20:51:21 939

原创 [leetcode] 287.Find the Duplicate Number

题目: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate element must exist. Assume that there is only one duplicate numbe

2015-09-28 13:25:09 1201 1

原创 [leetcode] 275.H-Index II

题目: Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? 题意: 这道题目是接274题而来,不过这次的引用次数是按照升序排列的。 思路: 可以使用二分查找的方法进行,扫描到middle元素的时候,如果middl

2015-09-05 17:00:53 934

原创 [leetcode] 274.H-Index

题目: Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.According to the definition of h-index on Wikipedia: “A

2015-09-05 16:58:02 1822

原创 [leetcode] 174.Dungeon Game

题目: The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially

2015-09-01 15:20:55 427

原创 [leetcode] 140.Word Break II

题目: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, given s = “cats

2015-09-01 14:03:34 356

原创 [leetcode] 139.Word Break

题目: 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, given s = “leetcode”, dict = [“leet”

2015-09-01 13:23:00 358

原创 [leetcode] 67.Add Binary

题目: Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”. 题意: 给定两个二进制的字符串,返回它们的和。 思路: 这道题目就是完成简单的二进制的加法。代码如下:class Solution {public:

2015-08-31 23:39:48 317

原创 [leetcode] 49.Group Anagrams

题目: Given an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ] Note: For t

2015-08-31 23:31:38 371

原创 [leetcode] 115.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 non

2015-08-31 22:36:46 376

原创 [leetcode] 72.Edit Distance

题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:

2015-08-31 19:12:24 304

原创 [leetcode] 28.Implement strStr()

题目: Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 题意: 实现strstr(),找到子串在原串中出现的第一个下标。 代码如下:class Solution {public: i

2015-08-31 18:50:32 281

原创 [leetcode] 97.Interleaving String

题目: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, return true. When s3 = “aadbbbaccc”, return

2015-08-31 18:39:38 264

原创 [leetcode] 58.Length of Last Word

题目: 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 word is defin

2015-08-31 17:31:15 248

原创 [leetcode] 14.Longest Common Prefix

题目: Write a function to find the longest common prefix string amongst an array of strings. 题意: 找出字符串的最长公共前缀。 思路: 只需要一个字符一个字符的去查看,第1~size-1的字符串这个位置上的字符是否与第0位上字符串上的字符是否相等。 以上。 代码如下:class Solution

2015-08-31 17:12:27 273

原创 [leetcode] 3.Longest Substring Without Repeating Characters

题目: 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 3.

2015-08-31 16:56:26 279

原创 [leetcode]32.Longest Valid Parentheses

题目: Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, whic

2015-08-31 16:02:20 423

原创 [leetcode] 76.Minimum Window Substring

题目: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example, S = “ADOBECODEBANC” T = “ABC” Minimum window is “BANC”.N

2015-08-31 14:04:53 581

原创 [leetcode] 273.Integer to English Words

题目: Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 2^31 - 1.For example, 123 -> “One Hundred Twenty Three” 12345 -> “Twelve Thousand Th

2015-08-31 10:56:46 1100

原创 [leetcode] 43.Multiply Strings

题目: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative. 题意: 给定两个字符串形式的整数,每个整数都是非负的,并且是任意大的。求出两

2015-08-31 00:33:32 330

原创 [leetcode] 10.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 entire input s

2015-08-30 21:19:51 273

原创 [leetcode] 93.Restore IP Addresses

题目: Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example: Given “25525511135”,return [“255.255.11.135”, “255.255.111.35”]. (Order does

2015-08-30 16:02:50 245

原创 [leetcode] 151.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”.题意: 给定一个字符串,将里面的单词进行反转。比如第一个单词会变成最后一个单词,最后一个单词会变成第一个单词。 思路: 这道题目只需要先将

2015-08-30 14:10:46 267

原创 [leetcode] 12.Integer to Roman

题目: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999. 题意: 给定一个数字,转化为罗马数字。 思路: 我们先打表,将个十百千位上整数对应的罗马数字打出。然后每一位只要从表中取就行了。 代码如下:class Solution

2015-08-30 13:48:31 276

原创 [leetcode] 13.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:1 V:5 X:10 L:50 C:100 D:500 M:

2015-08-30 13:31:03 281

原创 [leetcode] 71.Simplify Path

题目: Given an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c” 题意: 给定一个Unix风格的路径,简化它。 例子如上。 思路: 处理这类题目就是要处理好不同的细节。比如”

2015-08-30 11:55:08 620

原创 [leetcode] 8.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 ca

2015-08-30 11:30:39 231

原创 [leetcode] 125.Valid Palindrome

题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is not a

2015-08-29 23:41:18 229

原创 [leetcode] 20.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

2015-08-29 20:15:06 231

原创 [leetcode] 141.Linked List Cycle

题目: Given a linked list, determine if it has a cycle in it. 题意: 判断一个链表是否存在环。 思路: 使用快慢两个指针,一个一次走一步,一个一次走两步。 代码如下:/** * Definition for singly-linked list. * struct ListNode { * int val; *

2015-08-29 17:28:38 242

空空如也

空空如也

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

TA关注的人

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