自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [Leetcode]Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku

2015-03-26 05:01:12 411

原创 [Leetcode]Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element

2015-03-26 01:13:27 368

原创 [Leetcode]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-26 01:06:47 357

原创 [Leetcode]Word Ladder

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m

2015-03-25 06:07:04 404

原创 [Leetcode]Palindrome Partitioning II

Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Retu

2015-03-25 01:22:00 335

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

2015-03-20 06:49:45 367

原创 [Leetcode]Merge k Sorted Lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个有序的链表~brute force的方法是把这k个链表一个一个的合并起来,如 k个链表为[l1, l2, l3, l4],可以先合并l1, l2,再把合并得到的链表与l3合并,最后再与

2015-03-19 08:05:25 293

原创 [Leetcode]Longest Substring with At Most Two Distinct Characters

Given a stringS, find the length of the longest substringTthat contains at most two distinct characters.For example,Given S= “eceba”,T is "ece" which its length is 3. 给定一个字符串S,找到最长

2015-03-18 04:54:02 330

原创 [Leetcode]Valid Number

Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo

2015-03-17 13:59:57 479

原创 [Leetcode]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", r

2015-03-14 05:03:58 306

原创 [Leetcode]Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o

2015-03-14 03:27:07 406

原创 [Leetcode]Pow(x, n)

Implement pow(x, n).用二分法~把x的n次方划分成两个x的n/2次方相乘,然后递归求解~注意n为负数的情况~代码复杂度为O(logn)~ 还可以加上越界的判断~class Solution: # @param x, a float # @param n, a integer # @return a float def pow(self,

2015-03-14 01:55:26 968

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

2015-03-13 05:20:21 395

原创 [Leetcode]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.大数乘法~依旧是从低位到高位进行运算,可以先把num1, num2反转以方

2015-03-13 04:28:45 312

原创 [Leetcode]Insert Interval

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E

2015-03-12 06:56:24 307

原创 [Leetcode]Merge Intervals

Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].要求合并若干个区间~记得先把intervals按start值排序~# Definitio

2015-03-11 06:21:52 376

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

2015-03-11 02:56:05 427

原创 [Leetcode]Permutation Sequence

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

2015-02-11 14:55:16 330

原创 [Leetcode]First Missing Positive

Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant

2015-02-10 22:21:12 353

原创 [Leetcode]Add Binary

Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".两个二进制数相加~ 做法和Add Two Numbers类似~从低位开始,一直相加并且维护进位~时间复杂度为O(max(m, n))~细节注意点:用list

2015-02-10 15:17:09 482

原创 [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 ca

2015-02-10 13:46:43 270

原创 [Leetcode]Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no

2015-02-09 22:11:49 480

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

2015-02-09 22:01:49 328

原创 [Leetcode]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".Clarification:What constitutes a word?A sequence of non-spac

2015-02-08 22:46:40 485

原创 [Leetcode]Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.

2015-02-08 22:29:10 454

原创 [Leetcode]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-02-08 17:14:49 306

原创 [Leetcode]Implement strStr()

Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the function had been updat

2015-02-08 15:58:47 218

原创 [Leetcode]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-02-08 10:43:40 313

原创 [Leetcode]Sort List

Sort a linked list in O(n log n) time using constant space complexity.链表排序~可以用merge sort~找到链表的中点,然后对左右进行递归,最后再把两段lists合并~Merge Sort的时间复杂度为O(nlogn)~class Solution: # @param head, a ListNode

2015-02-05 20:22:40 273

原创 [Leetcode]Jump Game II

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i

2015-02-05 16:55:01 270

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

2015-02-05 13:46:47 284

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

2015-02-04 16:40:11 288

原创 [Leetcode]Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i

2015-02-04 16:39:32 298

原创 [Leetcode]Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for you

2015-02-04 14:21:23 287

原创 [Leetcode]Longest Palindromic Substring

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.求最大长度的回文子串~比较直接的方法

2015-02-03 17:22:55 405

原创 [Leetcode]Candy

There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on

2015-02-03 13:33:16 331

原创 [Leetcode]Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.求所有的字符串的最长公共前缀~直接用brute force的解法~class Solution: # @return a string def longestCommonPrefix(self,

2015-02-02 23:12:22 409

原创 [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.把给定的罗马数字转成阿拉伯数字~先科普一下,罗马数字对于每个位有三个单位:1,5,10,对于1到9,表示方法如下:1-3:用1表示;4:1:5左边加一个1;5: 直接用

2015-02-02 22:39:07 256

原创 [Leetcode]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 "()",

2015-02-02 17:14:53 299

原创 [Leetcode]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, givens = "leetcode",dict = ["leet"

2015-02-02 15:24:03 285

空空如也

空空如也

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

TA关注的人

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