- 博客(28)
- 收藏
- 关注
原创 228. Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”].题目要求找出连续的区域,遍历一次数组就可以得到结果代码
2016-04-30 17:20:57 171
原创 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree:1 / \ 2 3 \ 5 All root-to-leaf paths are:[“1->2->5”, “1->3”]代码:/** * Definition for a bin
2016-04-30 16:27:54 160
原创 330. Patching Array
Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Retur
2016-04-30 00:11:18 196
原创 303. 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 sumRange(0, 5
2016-04-27 17:23:01 200
原创 334. Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, ksuch that arr[i] < arr[j] < arr[
2016-04-25 16:32:58 200
原创 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return 1
2016-04-24 09:06:47 149
原创 344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.代码:class Solution {public: string reverseString(string s) { int n=
2016-04-24 08:22:06 185
原创 327. Count of Range Sum
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j), incl
2016-04-21 22:41:25 239
原创 166. Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.For exam
2016-04-20 23:34:05 202
原创 200. Number of Islands
Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume
2016-04-20 00:13:31 340
原创 201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4. m,n同时向右移位直到m和n相等,用k记录移了多少位
2016-04-19 22:45:15 197
原创 新手用linux的记录(centOS6.5)
切换用户: su联网: 因为校园网要用锐捷连接,所以一开始要安装锐捷: 1.下载锐捷客户端; 2.打开终端,输入cd /目录名,进入到锐捷所在的目录; 3.输入chmod +x rjsupplicant.sh; 4.输入sudo ./rjsupplicant.sh -u 用户名 -p 密码 -d 1(需要输入当前用户密码,输入的时候不会有显示,当时迷惑了很久).解压tar+安装: 1.
2016-04-19 20:43:36 314
原创 225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. empty() – Return whether
2016-04-17 13:22:22 193
原创 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 list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16,
2016-04-16 11:16:09 182
原创 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 since it in
2016-04-16 11:07:12 194
原创 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 10 ugly
2016-04-16 11:02:01 170
原创 81. Search in Rotated Sorted Array II
Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array.代码
2016-04-15 16:19:42 221
原创 219. Contains Duplicate II
Given an array of integers and an integer k, find out whether 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 k.方法1:使用map(7
2016-04-15 14:43:44 189
原创 279. 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, return
2016-04-15 13:59:11 440
原创 238. 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
2016-04-13 23:10:28 282
原创 208. Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note: You may assume that all inputs are consist of lowercase letters a-z.
2016-04-13 20:23:58 218
原创 74. 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
2016-04-12 17:04:02 302
原创 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 contiguous subarray [4,−1,2,1] has t
2016-04-12 16:36:37 292
原创 242. 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
2016-04-12 16:15:45 286
原创 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], [6,5,7], [4,
2016-04-12 15:47:10 248
原创 241. 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-
2016-04-10 21:10:52 280
原创 316. Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order am
2016-04-09 22:46:02 182
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人