ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p61

发表于 2017-03-14 | 分类于 blog

LeetCode p61 Rotate List 题解

1.题目:

Given a list, rotate the list to the right by k places, where k is non-negative.

For example:
Given 1->2->3->4->5->NULL and k = 2,
return 4->5->1->2->3->NULL.

阅读全文 »

p98

发表于 2017-03-13 | 分类于 blog

LeetCode p98 Validate Binary Search Tree 题解

1.题目:

Given a binary tree, determine if it is a valid binary search tree (BST).

Assume a BST is defined as follows:

The left subtree of a node contains only nodes with keys less than the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
Both the left and right subtrees must also be binary search trees.
Example 1:
2
/ \
1 3
Binary tree [2,1,3], return true.
Example 2:
1
/ \
2 3
Binary tree [1,2,3], return false.

阅读全文 »

p103

发表于 2017-03-13 | 分类于 blog

LeetCode p103 Binary Tree Zigzag Level Order Traversal 题解

1.题目:

Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).

For example:
Given binary tree [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its zigzag level order traversal as:
[
[3],
[20,9],
[15,7]
]

阅读全文 »

p105

发表于 2017-03-13 | 分类于 blog

LeetCode p105 Construct Binary Tree from Preorder and Inorder Traversal 题解

1.题目:

Given preorder and inorder traversal of a tree, construct the binary tree.

阅读全文 »

p106

发表于 2017-03-12 | 分类于 blog

LeetCode p106 Construct Binary Tree from Inorder and Postorder Traversal 题解

1.题目:

Given inorder and postorder traversal of a tree, construct the binary tree.

阅读全文 »

p109

发表于 2017-03-11 | 分类于 blog

LeetCode p109 Convert Sorted List to Binary Search Tree 题解

1.题目:

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

阅读全文 »

p438

发表于 2017-02-26 | 分类于 blog

LeetCode p438 Find All Anagrams in a String 题解

1.题目:

Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.

Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.

The order of output does not matter.

Example 1:

Input:
s: “cbaebabacd” p: “abc”

Output:
[0, 6]

Explanation:
The substring with start index = 0 is “cba”, which is an anagram of “abc”.
The substring with start index = 6 is “bac”, which is an anagram of “abc”.
Example 2:

Input:
s: “abab” p: “ab”

Output:
[0, 1, 2]

Explanation:
The substring with start index = 0 is “ab”, which is an anagram of “ab”.
The substring with start index = 1 is “ba”, which is an anagram of “ab”.
The substring with start index = 2 is “ab”, which is an anagram of “ab”.

阅读全文 »

1234…33
ZhangMengRou

ZhangMengRou

ZMR小站

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