- 博客(32)
- 资源 (11)
- 收藏
- 关注
原创 [LeetCode] Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, t
2015-11-11 19:04:27 1622
原创 [LeetCode] Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).For e
2015-11-10 17:26:45 805
原创 [LeetCode] Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window mo
2015-11-10 16:45:11 990
原创 [LeetCode] Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5) -> -1 su
2015-11-10 15:09:10 8323
原创 [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 each co
2015-11-09 21:17:43 1670
原创 [LeetCode] Search a 2D Matrix
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 from left to right.The first integer of each row is
2015-11-09 21:02:06 756
原创 [LeetCode] Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1Input: "2
2015-11-09 18:08:20 4470
原创 [LeetCode] 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 ).Examp
2015-11-09 16:45:57 8798
原创 [LeetCode] Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false.Note: You may assume the s
2015-11-09 11:17:36 1851
原创 [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”]解题思路先序遍历,递归的过程中保存路径,遇到叶子节点时将路
2015-11-08 17:34:08 891
原创 [LeetCode] Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, r
2015-11-08 17:06:54 1487
原创 [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 = [1,
2015-11-08 14:59:22 1962
原创 [LeetCode] Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ex
2015-11-08 14:34:19 1517
原创 [LeetCode] Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me
2015-11-08 13:48:22 1297
原创 抽象工厂模式
定义:为创建一组相关或相互依赖的对象提供一个接口,而且无需指定他们的具体类。抽象工厂模式是工厂方法模式的升级版本,他用来创建一组相关或者相互依赖的对象。他与工厂方法模式的区别就在于,工厂方法模式针对的是一个产品等级结构;而抽象工厂模式则是针对的多个产品等级结构。在编程中,通常一个产品结构,表现为一个接口或者抽象类,也就是说,工厂方法模式提供的所有产品都是衍生自同一个接口或抽象类,而抽象工厂模式所提供
2015-11-08 13:20:00 756
原创 [LeetCode] Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly
2015-11-07 16:03:46 2382
原创 [LeetCode] Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it in
2015-11-07 15:40:56 1644
原创 [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 in li
2015-11-07 14:59:37 3083
原创 [LeetCode] Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231−12^{31} - 1.For example, 123 -> “One Hundred Twenty Three” 12345 -> “Twelve Thousa
2015-11-07 14:28:08 1946
原创 [LeetCode] H-Index II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?Hint:Expected runtime complexity is in O(log n) and the input is sorted.解题思路二分法。实现代码
2015-11-07 13:23:58 2130
原创 [LeetCode] 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 scien
2015-11-07 12:58:23 1789
原创 [LeetCode] First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the
2015-11-06 18:51:09 2249
原创 [LeetCode] Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, retu
2015-11-06 18:34:43 2409
原创 [LeetCode] Peeking Iterator
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation – it essentially peek() at the element that will be return
2015-11-06 17:59:25 2016
原创 [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 but "(]"
2015-11-06 16:57:31 1500
原创 [LeetCode] Move Zeroes
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your funct
2015-11-06 16:11:44 1713
原创 [LeetCode] Game of Life
According to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”Given a board with m by n ce
2015-11-05 22:02:45 1566
原创 [LeetCode] Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.Examples:
2015-11-04 19:56:42 1706
原创 [LeetCode] 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 is 3
2015-11-04 16:43:00 2449
原创 [LeetCode] Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be
2015-11-04 12:35:51 1821
原创 [LeetCode] 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], therefore
2015-11-03 19:52:17 2021
原创 [LeetCode] Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret number and ask your friend to guess it. Each time your friend guesses a number, you give a hint. The hint
2015-11-03 16:53:11 2423
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人