自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

leetcode 解题思路

FLAG必经之路

  • 博客(62)
  • 收藏
  • 关注

原创 Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() --...

2014-12-30 14:45:33 530

原创 Excel Sheet Column Number

Related to questionExcel 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 ->

2014-12-29 07:10:02 577

原创 Two Sum III - Data structure design

Design and implement a TwoSum class. It should support the following operations:addandfind.add- Add the number to an internal data structure.find- Find if there exists any pair of numbers whi

2014-12-26 09:47:58 1957

原创 Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB Credits:S

2014-12-21 12:48:04 538

原创 Word Ladder II

Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be changed at a time Each intermediate word must exi...

2014-12-20 15:40:16 669

原创 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.Show TagsHave you m

2014-12-20 12:26:24 411

原创 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.Note:You may no...

2014-12-20 09:56:48 409

原创 Permutation Sequence

The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123" "132" "213" "231"...

2014-12-20 09:18:53 594

原创 Reverse Nodes in k-Group

Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-out nodes in the end should remain as it is.

2014-12-20 06:03:55 388

原创 Decode Ways

A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the to...

2014-12-19 14:52:37 520

原创 Text Justification

Given an array of words and a lengthL, format the text such that each line has exactlyLcharacters and is fully (left and right) justified.You should pack your words in a greedy approach; that is,

2014-12-19 13:25:47 512

原创 Two Sum II - Input array is sorted

Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two num...

2014-12-19 10:12:59 1626

原创 Scramble String

Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr...

2014-12-19 08:01:40 517

原创 Substring with Concatenation of All Words

You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without

2014-12-19 05:57:19 423

原创 Max Points on a Line

Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Show TagsHave you met this question in a real interview?思路:基本思路是这样的, 每次

2014-12-18 14:22:35 381

原创 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".No...

2014-12-18 13:04:24 680

原创 Wildcard Matching

Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover ...

2014-12-18 09:28:06 560

原创 Fraction to Recurring Decimal

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.For

2014-12-18 05:51:16 817

原创 Compare Version Numbers

Compare two version numbersversion1andversion1.Ifversion1>version2return 1, ifversion1version2return -1, otherwise return 0.You may assume that the version strings are non-empty and cont

2014-12-17 06:36:39 742

原创 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...

2014-12-16 15:14:40 517

原创 Maximal Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 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...

2014-12-16 09:04:00 528

原创 Divide Two Integers

Divide two integerswithout using multiplication, division and mod operator.If it will overflow(exceeding 32-bit signed integer representation range), return2147483647The integer division should ...

2014-12-16 08:05:33 577

原创 Unique Binary Search Trees II

Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3

2014-12-15 15:25:22 479

原创 LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if th...

2014-12-15 14:50:00 496

原创 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.思路:首先建立一对一的关系,用hashmap保持住,然后再从头走到尾...

2014-12-15 12:38:42 451

原创 ZigZag Conversion

这道题是cc150里面的题目了,其实比较简单,只要看出来他其实每个zigzag是2*m-2个字符就可以,这里m是结果的行的数量。接下来就是对于每一行先把往下走的那一列的字符加进去,然后有往上走的字符再加进去即可。时间复杂度是O(n),空间复杂度是O(1),代码如下:n=5:0 8 16

2014-12-15 08:35:24 433

原创 Evaluate Reverse Polish Notation

Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+

2014-12-15 06:51:39 364

原创 Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Return 0 if the array contains less than 2 elements.ExampleExample 1:Input: [1, 9, 2, 5...

2014-12-14 15:40:35 870

原创 Word Search

Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or verticall...

2014-12-14 10:39:14 492

原创 Clone graph

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each nod...

2014-12-13 12:48:28 569

原创 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.ExampleExample 1:Input:"...

2014-12-12 16:08:51 576

原创 Read N Characters Given Read4 II - Call multiple times

The API:int read4(char *buf)reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the

2014-12-12 13:14:20 3862

原创 Read N Characters Given Read4

The API:int read4(char *buf)reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the

2014-12-12 12:09:11 6266

原创 Gray Code

 The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of...

2014-12-11 10:12:43 367

原创 Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit ...

2014-12-11 07:44:54 453

原创 Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possibl...

2014-12-10 16:21:20 616

原创 One Edit Distance

Given two strings S and T, determine if they are both one edit distance apart.思路:可以用edit distance 来计算最小值,但是time out现在用我看到的一种解法,recursion来做。用i, j 两个指针,从左边扫到右边,两个一起走。s.charAt(i) != t.charAt(j

2014-12-10 15:03:02 2413

原创 Missing Ranges

Given a sorted integer array where the range of elements are [lower,upper] inclusive, return its missing ranges.For example, given[0, 1, 3, 50, 75],lower= 0 andupper= 99, return["2", "4->49

2014-12-10 13:49:55 2429

原创 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)

2014-12-10 09:37:56 469

原创 Binary Tree Upside Down

Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin...

2014-12-09 14:02:17 865

空空如也

空空如也

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

TA关注的人

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