PikachuBLOG


  • 首页

  • 分类

  • 归档

  • 标签

  • 搜索

87. Scramble String

发表于 2017-08-09 | 分类于 LeetCode | 阅读次数
字数统计 1,609 | 阅读时长 7

87. Scramble String

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = “great”:

87-1-Scramble-String

To scramble the string, we may choose any non-leaf node and swap its two children.

For example, if we choose the node “gr” and swap its two children, it produces a scrambled string “rgeat”.

87-2-Scramble-String

We say that “rgeat” is a scrambled string of “great”.

Similarly, if we continue to swap the children of nodes “eat” and “at”, it produces a scrambled string “rgtae”.

87-3-Scramble-String

We say that “rgtae” is a scrambled string of “great”.
Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.

阅读全文 »

86. Partition List

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

86. Partition List

Given a linked list and a value x, partition(划分) it such that all nodes less than x come before nodes greater than or equal to x.

You should preserve(保持) the original(原始的) relative(相对的) order of the nodes in each of the two partitions.

For example,
Given 1->4->3->2->5->2 and x = 3,
return 1->2->2->4->3->5.

阅读全文 »

85. Maximal Rectangle

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

85. Maximal Rectangle

Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area.

阅读全文 »

84. Largest Rectangle in Histogram

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

84. Largest Rectangle in Histogram

Given n non - negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.

84-1-histogram

Above is a histogram where width of each bar is 1, given height = [2, 1, 5, 6, 2, 3].
84-2-histogram_area
The largest rectangle is shown in the shaded area, which has area = 10 unit.

For example,
Given heights = [2, 1, 5, 6, 2, 3],
return 10.

阅读全文 »

83. Remove Duplicates from Sorted List

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

83. Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once.

For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.

阅读全文 »

82. Remove Duplicates from Sorted List II

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

82. Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

For example,
Given 1->2->3->3->4->4->5, return 1->2->5.
Given 1->1->1->2->3, return 2->3.

阅读全文 »

81. Search in Rotated Sorted Array II

发表于 2017-08-07 | 分类于 LeetCode | 阅读次数
字数统计 871 | 阅读时长 4

81. Search in Rotated Sorted Array II

Follow up for “Search in Rotated Sorted Array”:
  What if duplicates are allowed?
  Would this affect the run-time complexity? How and why?

Suppose an array sorted in ascending order 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).
Write a function to determine if a given target is in the array.
The array may contain duplicates.

阅读全文 »

80. Remove Duplicates from Sorted Array II

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

80. Remove Duplicates from Sorted Array II

Follow up for “Remove Duplicates”:
What if duplicates are allowed at most twice?

For example,
Given sorted array nums = [1,1,1,2,2,3],

Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3. It doesn’t matter what you leave beyond the new length.

阅读全文 »

79. Word Search

发表于 2017-08-07 | 分类于 LeetCode | 阅读次数
字数统计 1,308 | 阅读时长 7

79. Word Search

Given a 2D board and a word, find if the word exists in the grid.

The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.

For example,
Given board =
[
[‘A’,’B’,’C’,’E’],
[‘S’,’F’,’C’,’S’],
[‘A’,’D’,’E’,’E’]
]

word = “ABCCED”, -> returns true,
word = “SEE”, -> returns true,
word = “ABCB”, -> returns false.

阅读全文 »

78. Subsets

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

78. Subsets

Given a set of distinct integers, nums, return all possible subsets.

Note: The solution set must not contain duplicate subsets.

For example,
If nums = [1,2,3], a solution is:
[
  [3],
  [1],
  [2],
  [1,2,3],
  [1,3],
  [2,3],
  [1,2],
  []
]

阅读全文 »
1…91011…17
CodePikachu

CodePikachu

技术随笔

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