ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p167

发表于 2016-08-19 | 分类于 blog

LeetCode p167 Two Sum II - Input array is sorted 题解

1.题目:

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2

阅读全文 »

p326

发表于 2016-08-19 | 分类于 blog

LeetCode p326 Power of Three 题解

1.题目:

Given an integer, write a function to determine if it is a power of three.

阅读全文 »

p309

发表于 2016-08-19 | 分类于 blog

LeetCode p309 Best Time to Buy and Sell Stock with Cooldown 题解

1.题目:

Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times) with the following restrictions:
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
After you sell your stock, you cannot buy stock on next day. (ie, cooldown 1 day)
Example:
prices = [1, 2, 3, 0, 2]
maxProfit = 3
transactions = [buy, sell, cooldown, buy, sell]

阅读全文 »

p96

发表于 2016-08-19 | 分类于 blog

LeetCode p96 Unique Binary Search Trees 题解

1.题目:

Given n, how many structurally unique BST’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
\ / / / \ \
3 2 1 1 3 2
/ / \ \
2 1 2 3

阅读全文 »

p108

发表于 2016-08-19 | 分类于 blog

LeetCode p108 Convert Sorted Array to Binary Search Tree 题解

1.题目:

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

阅读全文 »

p216

发表于 2016-08-18 | 分类于 blog

LeetCode p216 Combination Sum III 题解

1.题目:

Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Example 1:
Input: k = 3, n = 7
Output:
[[1,2,4]]
Example 2:
Input: k = 3, n = 9
Output:
[[1,2,6], [1,3,5], [2,3,4]]

阅读全文 »

p137

发表于 2016-08-17 | 分类于 blog

LeetCode 137 Single Number II 题解

1.题目:

Given an array of integers, every element appears three times except for one. Find that single one.

阅读全文 »

1…222324…33
ZhangMengRou

ZhangMengRou

ZMR小站

230 日志
4 分类
14 标签
© 2019 ZhangMengRou
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4