- 博客(23)
- 收藏
- 关注
原创 [LeetCode]Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2015-05-29 20:50:12 314
原创 [LeetCode]Contains Duplicate II
Given an array of integers and an integer k, return true if and only if there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most
2015-05-29 12:35:42 316
原创 [LeetCode]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 st
2015-05-28 11:31:55 474
原创 [LeetCode]Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].思路:暴力求解,遍
2015-05-27 13:04:16 391
原创 [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-05-26 11:12:37 392
原创 [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-05-25 19:39:33 363
原创 [LeetCode]Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element
2015-05-25 19:19:04 347
原创 [LeetCode]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() -- Get
2015-05-24 20:50:12 387
原创 [LeetCode]Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3
2015-05-24 19:07:18 367
原创 [LeetCode]Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.[LeetCode Source]分析:所谓Anagrams指的是回文构词法。就是两个字符串所有的字符相同但是位置不同。比如”eat"和“tea"。
2015-05-23 14:28:15 438
原创 [LeetCode]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. Fo
2015-05-22 14:20:28 367
原创 [LeetCode]Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu
2015-05-21 21:15:26 328
原创 [LeetCode]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, givens = "
2015-05-21 20:17:03 446
原创 [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-05-21 10:30:16 327
原创 [LeetCode]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-05-21 09:46:22 277
原创 [Python]快速排序
最近摸了下Pyhton,发现真心好用。写下快排来练手。import randomdef partition(a,lo,hi): i = lo j = hi+1 v = a[lo] while True: while a[i]<v: i = i+1 if i == hi: break j = j-1 ##特别注意 whil
2015-05-10 14:32:23 1300
原创 [LeetCode]Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur
2015-05-09 13:35:36 282
原创 [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-05-09 13:33:08 258
原创 [LeetCode]Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers
2015-05-09 13:29:07 403
原创 [LeetCode]Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2015-05-09 13:21:47 384
原创 [LeetCode]Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \
2015-05-09 13:14:26 389
原创 [LeetCode]Reverse Linked List
Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?非递归:找好链表关系不难解决:/** * Definition for
2015-05-05 16:41:57 366
原创 [LeetCode]Isomorphic Strings
Given two strings s and t, 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 anot
2015-05-02 10:56:36 344
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人