- 博客(19)
- 收藏
- 关注
原创 275. 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.
2016-05-18 17:17:25 235
原创 290. 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.
2016-05-18 15:43:29 184
原创 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.T
2016-05-18 15:17:13 2857
原创 37. 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
2016-05-15 16:50:53 717
原创 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:
2016-05-14 17:32:12 290
原创 55. 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
2016-05-14 16:50:58 262
原创 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.求若干串字符串的最长共同前缀子串。直接每个字符串对比即可得到结果。代码:class Solution {public:string longestCommonPrefix(vector& strs){
2016-05-14 15:57:57 211
原创 41. 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
2016-05-14 15:39:35 177
原创 155. 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
2016-05-11 17:22:23 189
原创 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".Update (2015-02-12):For C programmers: Try to solve it in-place in
2016-05-11 16:18:47 479
原创 206. Reverse Linked List
Reverse a singly linked list.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?题目要求将一个单链表逆置,可以用迭代的方法,也可以用递归的方法。迭代的方法:class Solution {pu
2016-05-08 23:39:52 169
原创 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number of u
2016-05-08 21:51:47 649
原创 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?用动态规划做,然后发现其实就是斐波那契数列。
2016-05-08 16:17:54 188
原创 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.BFS:class Solution {public:
2016-05-08 12:07:05 173
原创 315. Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new counts array.The counts array has the property where counts[i] is the number of smaller elements to the right ofnums[i].Example:
2016-05-05 22:06:28 960
原创 78. Subsets
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For
2016-05-04 15:18:29 324
原创 199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
2016-05-04 12:17:31 172
原创 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 scie
2016-05-04 08:48:41 279
原创 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 sequence must be the sum of the preceding two.
2016-05-01 18:49:36 223
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人