- 博客(48)
- 收藏
- 关注
原创 551. Student Attendance Record I
551. Student Attendance Record I You are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent. 'L'
2017-05-17 15:44:51 191
原创 563. Binary Tree Tilt
563. Binary Tree Tilt Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as theabsolute difference between the sum of all left subtree node values
2017-05-17 14:58:02 150
原创 553. Optimal Division
553. Optimal DivisionGiven a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at a
2017-05-16 14:47:27 189
原创 575. Distribute Candies
575. Distribute CandiesGiven an integer array with even length, where different numbers in this array represent differentkinds of candies. Each number means one candy of the corresponding kind. Yo
2017-05-16 11:43:47 197
原创 566. Reshape the Matrix
566. Reshape the MatrixIn MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix
2017-05-16 11:14:42 176
原创 561. Array Partition I
561. Array Partition I Given an array of 2n integers, your task is to group these integers inton pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi)
2017-05-16 10:14:22 146
原创 313. Super Ugly Number
313. Super Ugly Number Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime listprimes of sizek.
2017-05-06 22:29:06 130
原创 264. Ugly Number II
264. Ugly Number II Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example,1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is
2017-05-06 21:40:28 160
原创 263. Ugly Number
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 include2, 3, 5. For example,6, 8 are u
2017-05-06 21:37:30 170
原创 64. Minimum Path Sum
64. Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only
2017-04-24 00:01:05 120
原创 63. Unique Paths II
道题中与其上一道Unique Paths不同之处是中途有了障碍,与上题的方程相同f[i][j] = f[i - 1][j] + f[i][j - 1],只不过在边缘时,即i=0或者j=0时,如果出现0,则其后都为0。不是边缘的位置有障碍则f[i][j]=0。class Solution {public: int uniquePathsWithObstacles(vector>& obsta
2017-04-23 23:33:52 105
原创 120. Triangle
这道题是说求从三角形顶端到低端路径数字之和的最小值,我的想法是两个数组分别表示上一行和当前行,计算两层的和,以此类推,最后一行的时候找到最小值即为所求。class Solution {public: int minimumTotal(vector>& triangle) { int m = triangle.size(); if (m == 1) return triangle[0
2017-04-22 20:06:47 132
原创 240. Search a 2D Matrix II
240. Search a 2D Matrix II Write an efficient algorithm that searches for a value in anm xn matrix. This matrix has the following properties:Integers in each row are sorted in ascen
2017-04-21 19:29:05 118
原创 74. Search a 2D Matrix
74. Search a 2D MatrixWrite an efficient algorithm that searches for a value in anm xn matrix. This matrix has the following properties:Integers in each row are sorted from left to right
2017-04-21 19:03:12 130
原创 62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach th
2017-04-21 14:38:07 136
原创 96. Unique Binary Search Trees
Given n, how many structurally uniqueBST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \
2017-04-21 13:42:46 171
原创 53. Maximum Subarray
53. Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the
2017-04-20 11:07:02 124
原创 260. Single Number III
260. 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 o
2017-04-18 14:58:56 155
原创 137. Single Number II
137. Single Number II Given an array of integers, every element appearsthree times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have
2017-04-18 14:17:18 153
原创 136. Single Number
136. Single Number Given an array of integers, every element appearstwice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could yo
2017-04-18 13:29:35 160
原创 213. House Robber II
213. House Robber II Note: This is an extension ofHouse Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not
2017-04-17 23:09:31 152
原创 198. House Robber
198. House Robber You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing eac
2017-04-17 23:00:26 148
原创 122. Best Time to Buy and Sell Stock II
122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may
2017-04-15 21:12:32 136
原创 121. Best Time to Buy and Sell Stock
121. Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on dayi.If you were only permitted to complete at most one transact
2017-04-15 16:21:58 150
原创 13. Roman to Integer
13. Roman to Integer Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 罗马数字构成规则: 相同的数字连写,所表示的数等于这些数字相加得到的数,如 Ⅲ=3;
2017-04-14 16:27:55 257
原创 537. Complex Number Multiplication
537. Complex Number Multiplication Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definit
2017-04-14 16:01:06 240
原创 215. Kth Largest Element in an Array
215. Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given
2017-04-13 15:42:37 191
原创 521. Longest Uncommon Subsequence I
521. Longest Uncommon Subsequence I Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is define
2017-04-12 11:16:11 229
原创 557. Reverse Words in a String III
557. Reverse Words in a String III Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:
2017-04-12 10:57:03 224
原创 300. Longest Increasing Subsequence
300. 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 longes
2017-04-11 17:53:13 160
原创 160. Intersection of Two Linked Lists
160. Intersection of Two Linked Lists Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:
2017-04-11 13:18:42 127
原创 14. Longest Common Prefix
14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. 这个题是要求找出字符串数组中最长的公共前缀,我用最直观的想法一个字母一个字母的匹配,一旦匹配失败或者达到了某一字符串的边界即返回。
2017-04-11 12:53:08 193
原创 219. Contains Duplicate II
219. Contains Duplicate II Given an array of integers and an integer k, find out whether there are two distinct indicesi andj in the array such thatnums[i] = nums[j] and theabsolu
2017-04-10 11:04:30 209
原创 58. Length of Last Word
58. 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
2017-04-10 11:02:08 166
原创 67. Add Binary
67. Add Binary Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". 这个题是用字符串实现二进制加法。class Solution {public: string addB
2017-04-10 10:46:03 148
原创 205. Isomorphic Strings
205. Isomorphic Strings Given two strings s andt, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to gett.All occurrences of a cha
2017-04-09 15:53:11 197
原创 516. Longest Palindromic Subsequence
516. Longest Palindromic Subsequence Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input:
2017-04-08 18:38:43 145
原创 392. Is Subsequence
392. Is Subsequence Given a string s and a stringt, check ifs is subsequence oft.You may assume that there is only lower case English letters in boths andt.t is potentially
2017-04-08 15:59:36 116
原创 343. Integer Break
343. Integer Break Given a positive integer n, break it into the sum ofat least two positive integers and maximize the product of those integers. Return the maximum product you can get.
2017-04-07 15:37:10 136
原创 357. Count Numbers with Unique Digits
357. Count Numbers with Unique Digits Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the to
2017-04-07 14:52:37 143
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人