ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p279

发表于 2016-10-15 | 分类于 blog

LeetCode p279 Perfect Squares 题解

1.题目:

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 2 because 13 = 4 + 9.

阅读全文 »

p129

发表于 2016-10-15 | 分类于 blog

LeetCode p129 Sum Root to Leaf Numbers 题解

1.题目:

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.

An example is the root-to-leaf path 1->2->3 which represents the number 123.

Find the total sum of all root-to-leaf numbers.

For example,

1

/ \
2 3

The root-to-leaf path 1->2 represents the number 12.
The root-to-leaf path 1->3 represents the number 13.

Return the sum = 12 + 13 = 25.

阅读全文 »

p73

发表于 2016-10-14 | 分类于 blog

LeetCode p73 Set Matrix Zeroes 题解

1.题目:

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.

阅读全文 »

p232

发表于 2016-10-13 | 分类于 blog

LeetCode p232 Implement Queue using Stacks 题解

1.题目:

Implement the following operations of a queue using stacks.

push(x) -- Push element x to the back of queue.
pop() -- Removes the element from in front of queue.
peek() -- Get the front element.
empty() -- Return whether the queue is empty.
阅读全文 »

p284

发表于 2016-10-13 | 分类于 blog

LeetCode p284 Peeking Iterator 题解

1.题目:

Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation – it essentially peek() at the element that will be returned by the next call to next().

Here is an example. Assume that the iterator is initialized to the beginning of the list: [1, 2, 3].

Call next() gets you 1, the first element in the list.

Now you call peek() and it returns 2, the next element. Calling next() after that still return 2.

You call next() the final time and it returns 3, the last element. Calling hasNext() after that should return false.

阅读全文 »

p78

发表于 2016-10-13 | 分类于 blog

LeetCode p78 Subsets 题解

1.题目:

Given a set of distinct integers, nums, return all possible subsets.

Note: The solution set must not contain duplicate subsets.

For example,
If nums = [1,2,3], a solution is:

[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]

阅读全文 »

p162

发表于 2016-10-12 | 分类于 blog

LeetCode p162 Find Peak Element 题解

1.题目:

A peak element is an element that is greater than its neighbors.

Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.

The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.

You may imagine that num[-1] = num[n] = -∞.

For example, in array [1, 2, 3, 1], 3 is a peak element and your function should return the index number 2.

阅读全文 »

1…131415…33
ZhangMengRou

ZhangMengRou

ZMR小站

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