ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p74

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

LeetCode p74 Search a 2D Matrix 题解

1.题目:

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 is greater than the last integer of the previous row.

For example,

Consider the following matrix:

[
[1, 3, 5, 7],
[10, 11, 16, 20],
[23, 30, 34, 50]
]

Given target = 3, return true.

阅读全文 »

p398

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

LeetCode p398 Random Pick Index 题解

1.题目:

Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.
Note:
The array size can be very large. Solution that uses too much extra space will not pass the judge.
Example:
int[] nums = new int[] {1,2,3,3,3};
Solution solution = new Solution(nums);

// pick(3) should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.
solution.pick(3);

// pick(1) should return 0. Since in the array only nums[0] is equal to 1.
solution.pick(1);

阅读全文 »

p110

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

LeetCode p110 Balanced Binary Tree 题解

1.题目:

Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

阅读全文 »

p102

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

LeetCode p102 Binary Tree Level Order Traversal 题解

1.题目:

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).

For example:
Given binary tree [3,9,20,null,null,15,7],

3

/ \
9 20
/ \
15 7

return its level order traversal as:

[
[3],
[9,20],
[15,7]
]

阅读全文 »

p118

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

LeetCode p118 Pascal’s Triangle 题解

1.题目:

Given numRows, generate the first numRows of Pascal’s triangle.

For example, given numRows = 5,
Return

[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]

阅读全文 »

p154

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

LeetCode p154 Find Minimum in Rotated Sorted Array II 题解

1.题目:

Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
The array may contain duplicates.

阅读全文 »

p341

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

LeetCode p341 Flatten Nested List Iterator 题解

1.题目:

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 list [[1,1],2,[1,1]],

By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1].

Example 2:
Given the list [1,[4,[6]]],

By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6].

阅读全文 »

1…141516…33
ZhangMengRou

ZhangMengRou

ZMR小站

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