码迷,mamicode.com
首页 >  
搜索关键字:算法面试    ( 461个结果
LeetCode: Distinct Subsequences [115]
【题目】 Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relati...
分类:其他好文   时间:2014-06-29 07:27:17    阅读次数:210
LeetCode: Convert Sorted Array to Binary Search Tree [108]
【题目】 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 【题意】 给定一个已排序的数组(不存在重复元素),将它转换成一棵平衡二叉搜索树。 【思路】 由于平衡二叉树要求左右子树的高度差绝对值相遇等于1,也就是说左右子树尽可能包含相同数目节点。 则使用二分法来解本题即可。...
分类:其他好文   时间:2014-06-20 11:03:31    阅读次数:246
LeetCode: Balanced Binary Tree [110]
【题目】 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. 【题意】 判断二叉树是否是平衡二叉树 【思路】 平衡二...
分类:其他好文   时间:2014-06-20 11:02:54    阅读次数:173
LeetCode: Path Sum II [113]
【题目】 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / 4 8 / / 11 13 4 ...
分类:其他好文   时间:2014-06-20 10:53:08    阅读次数:181
[ LeetCode] Single Number
数组含有n个数,其中有一个数只出现1次,其余的数都出现两次,求只出现一次的数。 这个主要考察的是位运算中的异或运算的性质-----当两个相等的数做异或运算他们的值为0(a^a = 0)。本题中对数组中所有的数做异或,那么最后异或的结果就是只出现1次的数。思想很简单代码如下:...
分类:其他好文   时间:2014-06-20 10:02:03    阅读次数:281
LeetCode: Convert Sorted List to Binary Search Tree [109]
【题目】 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 【题意】 将一个有序链表转换成平衡二叉树 【思路】 思路跟Convert Sorted Array to Binary Search Tree完全一样...
分类:其他好文   时间:2014-06-07 16:20:05    阅读次数:287
LeetCode: Populating Next Right Pointers in Each Node [116]
【题目】 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be...
分类:其他好文   时间:2014-06-07 14:28:36    阅读次数:215
LeetCode: Flatten Binary Tree to Linked List [114]
【题目】 Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / 2 5 / \ 3 4 6 The flattened tree should look like: 1 2 3 4 \...
分类:其他好文   时间:2014-06-07 11:37:00    阅读次数:153
[LeetCode] Evaluate Reverse Polish Notation
计算逆波兰表达式,了解更多关于逆波兰表达式请点击。 计算逆波兰表达式这是个很典型的栈应用的例子。 解题方法就是用栈来处理,需要注意的是本题输入给的是字符串数组,所以需要在字符串和整数之间有个转换。...
分类:其他好文   时间:2014-06-04 14:06:18    阅读次数:318
[leetcode] Reverse Words in a String
翻转字符串中的单词顺序,这是个老题目了,但是leetcode上面的要求更为严格,如: 要求把开头和结尾的空格删除掉; 缩减单词间的空格数为1(如果有多个空格); 单词若全是空格,则返回一个空字符串(""). 此题思想不难,主要是注意上面三个要求和一些细节就可以AC。 大致分为两步:一个是常规的翻转字符串中的单词;另一个就是想方法去掉串中的多余的单词;这两步骤的顺序可以颠倒。...
分类:其他好文   时间:2014-06-04 13:47:30    阅读次数:405
461条   上一页 1 ... 35 36 37 38 39 ... 47 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!