leetcode50
文章平均质量分 59
mengq303
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
atoi
leetcode50题String to Integer的实现原创 2015-10-01 23:56:12 · 318 阅读 · 0 评论 -
循环数组左移
给定一个数组,左移k位。这一题,我开始是这样考虑的,每一位都应该直接移动到 (i-k+n)%n位。所以代码如下:import java.util.Scanner;public class Reverse { public String solve(char[] c, int k) { int i = 0; char temp = c[i]; int n = c.原创 2015-11-01 20:30:19 · 961 阅读 · 0 评论 -
Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.这一题好难啊。一点头绪都没有,要求是线性时间复杂度,同时要求常数项空间。答案上,是这样来的。使用了位运算。ps:感觉用到位运算的题目都好难。如果对所有数字的第i位bit进行统计的话,会发原创 2015-10-30 22:51:23 · 304 阅读 · 0 评论 -
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原创 2015-10-29 21:26:34 · 602 阅读 · 0 评论 -
Single Number
Given an array of integers, every element appears twice except for one. Find that single one.这一题第一反应是 直接存个map,作为键值对。但是这一题要求 不要有extra memory,同时时间复杂度为O(n);直接想到异或^,两个数相异为1,相同为0。所以把数组整个异或一遍,出来的值就是原创 2015-10-30 21:36:01 · 283 阅读 · 0 评论 -
Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin原创 2015-10-30 20:14:31 · 365 阅读 · 0 评论 -
Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.一开始的考虑很有问题,忘了考虑是到结点(左右子树都为空)的路径,所以原创 2015-10-28 16:36:22 · 282 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.和上一题不同的地方就在于这一题是sorted list 上一题是 sorted array比较无耻点,其实可以直接仿照之前的sorted array的方法:代码如下(有问原创 2015-10-29 20:18:06 · 299 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.原创 2015-10-29 20:10:34 · 343 阅读 · 0 评论 -
Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.原创 2015-10-28 17:02:55 · 300 阅读 · 0 评论 -
Validate Binary Search Tree
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.Th原创 2015-10-28 16:07:45 · 324 阅读 · 0 评论 -
Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.这一题很简单,就什么都不多说了。数的高度等于子树的高度(原创 2015-10-28 16:32:53 · 313 阅读 · 0 评论 -
Copy List with Random Pointer
题目:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.不要想的太复杂了。直接用个hash原创 2015-10-27 21:37:40 · 346 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.这题一开始一直TLE。后来查了下,发现是因为/** * Definition for singly-linked list. * public class ListNode { *原创 2015-10-27 20:59:15 · 310 阅读 · 0 评论
分享