- 博客(18)
- 收藏
- 关注
原创 [leetcode] 344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".这道题是颠倒字符串,题目难度为easy。题目比较简单就直接上代码了,具体代码:class Solutio
2016-04-29 18:48:47 325
原创 [leetcode] 35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2016-04-28 16:33:14 356
原创 [leetcode] 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-04-27 21:02:43 250
原创 [leetcode] 145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut
2016-04-26 19:37:35 449
原创 [leetcode] 345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".
2016-04-25 21:01:07 891
原创 [leetcode] 342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve it without
2016-04-22 10:12:16 310
原创 [leetcode] 68. Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i
2016-04-21 16:11:52 952
原创 [leetcode] 120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [
2016-04-20 21:08:02 267
原创 [leetcode] 341. Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Example 1:Given the li
2016-04-19 20:17:39 543
原创 [leetcode] 19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the
2016-04-18 20:34:04 291
原创 [leetcode] 278. 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
2016-04-14 21:55:28 442
原创 [leetcode] 264. 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
2016-04-14 20:52:07 299
原创 [leetcode] 329. Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside
2016-04-13 16:09:31 1044
原创 [leetcode] 229. Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.Hint:How many majority elements could it po
2016-04-11 11:36:10 816
原创 [leetcode] 263. 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 sinc
2016-04-08 11:48:00 256
原创 [leetcode] 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.这道题是合并k个已排序链表,题目难度为Hard。题目和21题(传送门)合并两个已排序链表相关,感兴趣的同学可以先看下21题。最直观的想法是将节点逐个存入堆中,然后再依次取出
2016-04-07 17:47:04 442
原创 [leetcode] 89. 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
2016-04-06 11:50:01 502
原创 [leetcode] 299. Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t
2016-04-05 19:20:20 285
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人