ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p11

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

LeetCode p11 Container With Most Water 题解

1.题目:

Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container.

阅读全文 »

p289

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

LeetCode p289 Game of Life 题解

1.题目:

According to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”

Given a board with m by n cells, each cell has an initial state live (1) or dead (0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):

Any live cell with fewer than two live neighbors dies, as if caused by under-population.
Any live cell with two or three live neighbors lives on to the next generation.
Any live cell with more than three live neighbors dies, as if by over-population..
Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

Write a function to compute the next state (after one update) of the board given its current state.

阅读全文 »

p386

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

LeetCode p386 Lexicographical Numbers 题解

1.题目:

Given an integer n, return 1 - n in lexicographical order.
For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].
Please optimize your algorithm to use less time and space. The input size may be as large as 5,000,000.

阅读全文 »

p101

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

LeetCode p101 Remove Symmetric Tree 题解

1.题目:

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

For example, this binary tree [1,2,2,3,4,4,3] is symmetric:

1

/ \
2 2
/ \ / \
3 4 4 3

But the following [1,2,2,null,3,null,3] is not:

1

/ \
2 2
\ \
3 3

阅读全文 »

p27

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

LeetCode p27 Remove Element 题解

1.题目:

Given an array and a value, remove all instances of that value in place and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
The order of elements can be changed. It doesn’t matter what you leave beyond the new length.
Example:
Given input array nums = [3,2,2,3], val = 3
Your function should return length = 2, with the first two elements of nums being 2.

阅读全文 »

p399

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

LeetCode p399 Kth Largest Element in an Array 题解

1.题目:

Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answer does not exist, return -1.0.
Example:
Given a / b = 2.0, b / c = 3.0.
queries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? .
return [6.0, 0.5, -1.0, 1.0, -1.0 ].
The input is: vector<pair<string, string>> equations, vector& values, vector<pair<string, string>> queries , where equations.size() == values.size(), and the values are positive. This represents the equations. Return vector.
According to the example above:
equations = [ [“a”, “b”], [“b”, “c”] ],
values = [2.0, 3.0],
queries = [ [“a”, “c”], [“b”, “a”], [“a”, “e”], [“a”, “a”], [“x”, “x”] ].
The input is always valid. You may assume that evaluating the queries will result in no division by zero and there is no contradiction.

阅读全文 »

p66

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

LeetCode p66 Plus One 题解

1.题目:

Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.

阅读全文 »

1…151617…33
ZhangMengRou

ZhangMengRou

ZMR小站

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