LeetCode
DoubleZ_kobe
爱篮球 爱健身 爱生活
展开
-
LeetCode:110. 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 dif原创 2015-12-30 10:36:07 · 294 阅读 · 0 评论 -
删除链表中倒数第n个节点
删除链表中倒数第n个节点15:00 开始计时给定一个链表,删除链表中倒数第n个节点,返回链表的头节点。您在真实的面试中是否遇到过这个题? Yes 注意事项链表中的节点个数大于等于n样例挑战标签相关题目 笔记给出链表1->2->3->4->5->nu原创 2016-03-04 14:37:26 · 364 阅读 · 0 评论 -
合并两个排序链表
将两个排序链表合并为一个新的排序链表您在真实的面试中是否遇到过这个题? Yes样例标签相关题目 笔记给出 1->3->8->11->15->null,2->null, 返回 1->2->3->8->11->15->null。根据题意,首先对于链表的遍历我首先想到用递归。即新建一个空链表Result 让result的头指针指向n原创 2016-03-05 22:02:09 · 221 阅读 · 0 评论 -
Print Numbers by Recursion
Print Numbers by RecursionPrint numbers from 1 to the largest number with N digits by recursion. NoticeIt's pretty easy to do recursion like:recursion(i) { if i > largest number:原创 2016-03-06 16:15:06 · 252 阅读 · 0 评论 -
Binary Tree Path Sum
给定一个二叉树,找出所有路径中各节点相加总和等于给定 目标值 的路径。一个有效的路径,指的是从根节点到叶节点的路径。您在真实的面试中是否遇到过这个题?样例标签相关题目笔记给定一个二叉树,和 目标值 = 5: 1 / \ 2 4 / \ 2 3返回:[ [1, 2, 2], [1,原创 2016-03-07 20:29:30 · 524 阅读 · 0 评论 -
字符串置换
给定两个字符串,请设计一个方法来判定其中一个字符串是否为另一个字符串的置换。置换的意思是,通过改变顺序可以使得两个字符串相等。样例标签相关题目笔记"abc" 为 "cba" 的置换。"aabc" 不是 "abcc" 的置换。对于由英文字母组成的字符串 可以下面方法 public boolean stringPermutation(S原创 2016-03-07 21:37:31 · 1444 阅读 · 0 评论 -
Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.Given binary tree {1,#,2,3}, 1 \ 2 / 3/** * Created by JZloveSnow on 16/3/7. */class Solu原创 2016-03-07 21:54:24 · 278 阅读 · 0 评论 -
带最小值操作的栈
实现一个带有取最小值min方法的栈,min方法将返回当前栈中的最小值。你实现的栈将支持push,pop 和 min 操作,所有操作要求都在O(1)时间内完成。 注意事项如果堆栈中没有数字则不能进行min方法的调用样例标签相关题目 笔记如下操作:push(1),pop(),push(2),push(3),min(), pus原创 2016-03-09 11:31:45 · 367 阅读 · 0 评论 -
二叉树的层次遍历
给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问)给一棵二叉树 {3,9,20,#,#,15,7} : 3 / \9 20 / \ 15 7返回他的分层遍历结果:[ [3], [9,20], [15,7]]import java.util.*;import java.util.Queue;/** * Created原创 2016-03-09 11:08:58 · 267 阅读 · 0 评论 -
Intersection of Two Linked Lists
160. Intersection of Two Linked ListsMy SubmissionsQuestionTotal Accepted: 65866 Total Submissions: 218868 Difficulty: EasyWrite a program to find the node at which the interse原创 2016-03-11 10:37:18 · 251 阅读 · 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.Have you met this question in a real i原创 2016-03-11 21:18:21 · 297 阅读 · 0 评论 -
Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Have you met this question in a real interview?Clarifi原创 2016-03-11 21:44:08 · 329 阅读 · 0 评论 -
A + B Problem
Write a function that add two numbers A and B. You should not use + or any arithmetic operators.NoticeThere is no need to read data from standard input stream. Both parameters are given in f原创 2016-03-12 15:15:27 · 397 阅读 · 0 评论 -
搜索区间
给定一个包含 n 个整数的排序数组,找出给定目标值 target 的起始和结束位置。如果目标值不在数组中,则返回[-1, -1]给出[5, 7, 7, 8, 8, 10]和目标值target=8,返回[3, 4]思想就是分布解答 ,针对数组为空的情况 返回【-1,-1】 数组中元素只有一个 或者数组中全部元素相同 记录count 利用Java的ArrayL原创 2016-03-12 16:37:27 · 660 阅读 · 0 评论 -
最大子数组
给定一个整数数组,找到一个具有最大和的子数组,返回其最大和。样例挑战标签相关题目笔记给出数组[−2,2,−3,4,−1,2,1,−5,3],符合要求的子数组为[4,−1,2,1],其最大和为6累加和sum 如果sum0 继续加 然后返回最大值 代码如下/** * Created by jason on 2016/3/14. */c原创 2016-03-14 21:53:51 · 1785 阅读 · 4 评论 -
反转单链表
2 方法1:就地反转法2.1 思路把当前链表的下一个节点pCur插入到头结点dummy的下一个节点中,就地反转。dummy->1->2->3->4->5的就地反转过程:dummy->2->1->3->4->5dummy->3->2->1->4->5dummy->4>-3->2->1->5dummy->5->4->3->2->12.2 解释1初始状态原创 2016-03-04 14:35:48 · 310 阅读 · 0 评论 -
Implement Queue by Two Stacks
Implement Queue by Two StacksShow result 30:00 StartAs the title described, you should only use two stacks to implement a queue's actions.The queue should support push(el原创 2016-03-03 12:09:38 · 233 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].递归喽public class Sol原创 2016-03-03 11:18:02 · 210 阅读 · 0 评论 -
LeetCode : 101. Symmetric Tree
LeetCode 101 对称树比较简单的题目 利用递归-分治方法解决就ok了(虽然递归很占内存...) 直接看代码吧public int depth(TreeNode root) { if(root == null) { return 0; }else { int leftLength = depth(root.原创 2015-12-30 21:37:19 · 315 阅读 · 0 评论 -
LeetCode : 258. Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on原创 2015-12-30 21:41:25 · 229 阅读 · 0 评论 -
104. 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.很明显,使用递归喽!class TreeNode {原创 2015-12-30 21:43:43 · 316 阅读 · 0 评论 -
226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node. * public class TreeNode { *原创 2015-12-30 21:45:34 · 209 阅读 · 0 评论 -
100. Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Def原创 2015-12-30 21:51:48 · 198 阅读 · 0 评论 -
27. Remove Element
给定一个数组和一个值,删除该值的所有实例并返回新的长度。Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you l原创 2015-12-31 10:49:07 · 220 阅读 · 0 评论 -
LeetCode:198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2016-01-05 15:44:20 · 191 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2016-01-05 16:05:50 · 201 阅读 · 0 评论 -
112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2016-01-06 10:26:58 · 211 阅读 · 0 评论 -
LeetCode : 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.“回文”是指正读反读都能读通的句子,它是古今中外都有的一种修辞方式和文字游戏,如“我为人人,人人为我”等。在数学中也有这样一类数字有这样的特征,成为回文数(palindrome number)。设n是一任意自然数。若将n的各位数字反向排列所得自原创 2016-01-06 15:45:17 · 377 阅读 · 0 评论 -
Lee天Code : 111. 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.遇到此种二叉树遍历深度的题目,应该想到要用递归最为合适。我们用递归来原创 2016-01-07 11:26:16 · 319 阅读 · 0 评论 -
LeetCode:219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.查原创 2016-01-10 10:52:45 · 255 阅读 · 0 评论 -
Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.二分查找public class Soluti原创 2016-03-03 10:21:29 · 199 阅读 · 0 评论 -
144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].递归class Solution60原创 2016-03-03 10:50:36 · 181 阅读 · 0 评论 -
面试杂谈
今天和大家分享一下我的面试经历吧,希望能对你有所帮助! BTW: bo主已经收到百度offer 饿了么offer等 最终选择百度bo主北邮研究僧,过完年后来三月份就开始写简历 刷各种题,为了找到好实习而准备着。我们实验室主要做SDN+光,语言大多都是java所以自然就想去互联网实习增长专业技能呗。找实习之前就狂刷leetcode、poj、牛客,各种java的高级特性等等。有些东西你平时做原创 2016-05-03 10:12:09 · 690 阅读 · 0 评论