ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p352

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

LeetCode p352 Data Stream as Disjoint Intervals 题解

1.题目:

Given a data stream input of non-negative integers a1, a2, …, an, …, summarize the numbers seen so far as a list of disjoint intervals.
For example, suppose the integers from the data stream are 1, 3, 7, 2, 6, …, then the summary will be:
[1, 1]
[1, 1], [3, 3]
[1, 1], [3, 3], [7, 7]
[1, 3], [7, 7]
[1, 3], [6, 7]

阅读全文 »

p202

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

LeetCode p202 Happy Number 题解

1.题目:

Write an algorithm to determine if a number is “happy”.
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.
Example: 19 is a happy number
12 + 92 = 82
82 + 22 = 68
62 + 82 = 100
12 + 02 + 02 = 1

阅读全文 »

p392

发表于 2016-09-05 | 分类于 blog

LeetCode p392 Is Subsequence 题解

1.题目:

Given a string s and a string t, check if s is subsequence of t.
You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, and s is a short string (<=100).
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, “ace” is a subsequence of “abcde” while “aec” is not).
Example 1:
s = “abc”, t = “ahbgdc”
Return true.
Example 2:
s = “axc”, t = “ahbgdc”
Return false.

阅读全文 »

p231

发表于 2016-09-05 | 分类于 blog

LeetCode p231 Power of Two 题解

1.题目:

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

阅读全文 »

p241

发表于 2016-09-05 | 分类于 blog

LeetCode p241 Different Ways to Add Parentheses 题解

1.题目:

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and .
Example 1
Input: “2-1-1”.
((2-1)-1) = 0
(2-(1-1)) = 2
Output: [0, 2]
Example 2
Input: “2
3-45”
(2
(3-(45))) = -34
((2
3)-(45)) = -14
((2
(3-4))5) = -10
(2
((3-4)5)) = -10
(((2
3)-4)*5) = 10
Output: [-34, -14, -10, -10, 10]

阅读全文 »

p389

发表于 2016-09-02 | 分类于 blog

LeetCode p389 Find the Difference 题解

1.题目:

Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
Example:
Input:
s = “abcd”
t = “abcde”
Output:
e

阅读全文 »

p337

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

LeetCode p337 House Robber III 题解

1.题目:

The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that “all houses in this place forms a binary tree”. It will automatically contact the police if two directly-linked houses were broken into on the same night.

Determine the maximum amount of money the thief can rob tonight without alerting the police.

Example 1:

 3
/ \

2 3
\ \
3 1

Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.

Example 2:

 3
/ \

4 5
/ \ \
1 3 1

Maximum amount of money the thief can rob = 4 + 5 = 9.

阅读全文 »

1…212223…33
ZhangMengRou

ZhangMengRou

ZMR小站

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