PikachuBLOG


  • 首页

  • 分类

  • 归档

  • 标签

  • 搜索

131. Palindrome Partitioning

发表于 2017-08-22 | 分类于 LeetCode | 阅读次数
字数统计 376 | 阅读时长 2

131. Palindrome Partitioning

Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.

For example, given s = “aab”,
Return
[
  [“aa”,”b”],
  [“a”,”a”,”b”]
]

阅读全文 »

129. Sum Root to Leaf Numbers

发表于 2017-08-21 | 分类于 LeetCode | 阅读次数
字数统计 645 | 阅读时长 3

129. Sum Root to Leaf Numbers

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.

1
2
3
4
5
6
7
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.
阅读全文 »

125. Valid Palindrome

发表于 2017-08-21 | 分类于 LeetCode | 阅读次数
字数统计 273 | 阅读时长 1

125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

For example,
“A man, a plan, a canal: Panama” is a palindrome.
“race a car” is not a palindrome.

Note:
Have you consider that the string might be empty ? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.

阅读全文 »

124. Binary Tree Maximum Path Sum

发表于 2017-08-21 | 分类于 LeetCode | 阅读次数
字数统计 410 | 阅读时长 2

124. Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum.

For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path does not need to go through the root.

1
2
3
4
5
6
For example:
Given the below binary tree,
1
/ \
2 3
Return 6.
阅读全文 »

123. Best Time to Buy and Sell Stock III

发表于 2017-08-21 | 分类于 LeetCode | 阅读次数
字数统计 1,008 | 阅读时长 5

123. Best Time to Buy and Sell Stock III

Say you have an array for which the ith element is the price of a given stock on day i.

Design an algorithm to find the maximum profit. You may complete at most two transactions.

Note:
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

阅读全文 »

122. Best Time to Buy and Sell Stock II

发表于 2017-08-21 | 分类于 LeetCode | 阅读次数
字数统计 593 | 阅读时长 3

122. Best Time to Buy and Sell Stock II

Say you have an array for which the ith element is the price of a given stock on day i.

Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

阅读全文 »

121. Best Time to Buy and Sell Stock

发表于 2017-08-21 | 分类于 LeetCode | 阅读次数
字数统计 533 | 阅读时长 2

121. Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Example 1:
Input: [7, 1, 5, 3, 6, 4]
Output: 5
max. difference = 6-1 = 5 (not 7-1 = 6, as selling price needs to be larger than buying price)

Example 2:
Input: [7, 6, 4, 3, 1]
Output: 0
In this case, no transaction is done, i.e. max profit = 0.

阅读全文 »

120. Triangle

发表于 2017-08-19 | 分类于 LeetCode | 阅读次数
字数统计 601 | 阅读时长 3

120. Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.

1
2
3
4
5
6
7
8
For example, given the following triangle
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).

Note:
Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.

阅读全文 »

119. Pascal's Triangle II

发表于 2017-08-19 | 分类于 LeetCode | 阅读次数
字数统计 319 | 阅读时长 1

119. Pascal’s Triangle II

Given an index k, return the kth row of the Pascal’s triangle.

For example, given k = 3,
Return [1,3,3,1].

Note:
Could you optimize your algorithm to use only O(k) extra space?

阅读全文 »

118. Pascal's Triangle

发表于 2017-08-18 | 分类于 LeetCode | 阅读次数
字数统计 248 | 阅读时长 1

118. Pascal’s Triangle

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]
]

阅读全文 »
1…567…17
CodePikachu

CodePikachu

技术随笔

168 日志
5 分类
7 标签
RSS
GitHub Twitter 微博 知乎
0%
© 2015 - 2020 CodePikachu
博客全站共123.3k字
本站访客数:
由 Hexo 强力驱动
主题 - NexT.Pisces