ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p51

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

LeetCode 51 N-Queens 题解

1.题目:

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

阅读全文 »

p347

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

LeetCode 347 Top K Frequent Elements 题解

1.题目:

Given a non-empty array of integers, return the k most frequent elements.
For example,
Given [1,1,1,2,2,3] and k = 2, return [1,2].

阅读全文 »

p384

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

LeetCode 384 Shuffle an Array 题解

1.题目:

Shuffle a set of numbers without duplicates.
Example:
// Init an array with set 1, 2, and 3.
int[] nums = {1,2,3};
Solution solution = new Solution(nums);
// Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3] must equally likely to be returned.
solution.shuffle();
// Resets the array back to its original configuration [1,2,3].
solution.reset();
// Returns the random shuffling of array [1,2,3].
solution.shuffle();

阅读全文 »

p383

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

LeetCode 383 Ransom Note 题解

1.题目:

canConstruct(“a”, “b”) -> false
canConstruct(“aa”, “ab”) -> false
canConstruct(“aa”, “aab”) -> true

阅读全文 »

p382

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

LeetCode 382 Linked List Random Node 题解

1.题目:

Given a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen.
Follow up:
What if the linked list is extremely large and its length is unknown to you? Could you solve this efficiently without using extra space?
Example:
// Init a singly linked list [1,2,3].
ListNode head = new ListNode(1);
head.next = new ListNode(2);
head.next.next = new ListNode(3);
Solution solution = new Solution(head);
// getRandom() should return either 1, 2, or 3 randomly. Each element should have equal probability of returning.
solution.getRandom();

阅读全文 »

p35

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

LeetCode 35 Search Insert Position 题解

1.题目:

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Here are few examples.
[1,3,5,6], 5 → 2
[1,3,5,6], 2 → 1
[1,3,5,6], 7 → 4
[1,3,5,6], 0 → 0

阅读全文 »

p34

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

LeetCode 34 Search for a Range 题解

1.题目:

Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm’s runtime complexity must be in the order of O(log n).
If the target is not found in the array, return [-1, -1].
For example,
Given [5, 7, 7, 8, 8, 10] and target value 8,
return [3, 4].

阅读全文 »
1…242526…33
ZhangMengRou

ZhangMengRou

ZMR小站

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