- 博客(7)
- 收藏
- 关注
原创 recover-binary-search-tree && validate-binary-search-tree
题目:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n ) space is pretty straight forward. Could you devise...
2019-04-11 15:47:02 126
原创 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.简单的递归实现,dfs递归+快慢指针不同场景中快慢指针方法具体细节可能不同,例如这里:1->2->3,返回的是2,1->2,返回的是2。另外场景...
2019-04-09 14:46:05 123
原创 二叉树求最大值路径
比较简单的二叉树题目,一开始以为需要找从叶节点到另一个叶节点的路径的最大值,但题目实际上说start|end可以是任意节点,实现过程稍微有点不一样,不过思路大致是相同的。题目:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For examp...
2019-04-08 11:27:07 1435
原创 word-ladder
题目描述Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate wo...
2019-04-08 07:35:20 242
原创 回文求最小分割数-回文求所有有效分割
回文相关的题目算是算法基础中的基础了。发现工作后如果不是算法岗,算法能力和算法敏感度真的是会下降,平时mark一些经典算法题有利于保持状态。题目一:求sentence中的最小分割数,使得分割后所有字符串都是回文。Given a string s, partition s such that every substring of the partition is a palindrome....
2019-04-08 00:05:28 315
原创 二叉树所有路径的值的和
一道很简单的题目,这里只是对比一下几种思路和做法。题目很简单,就是一颗二叉树由0-9数字构成,求所有root->leaf路径组成的数的总和。Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-t...
2019-04-07 23:48:20 1453
原创 求数列中唯一的数--singleNumber
很久没有写关于算法题的了。这里写一下一个非常简单但又很经典的算法题。主要过程是利用bit和数位运算去求数列中的唯一的数。题目一:一个数列中,有一个数只出现了一次,其它数全都出现了两次,求这个数。要求一次遍历,常量extra空间。题目二:一个数列中,有一个数出现了一次或两次,其它数全都出现了三次,求这个数。要求一次遍历,常量extra空间。题目一比较简单,如果一个bit出现两次就归0,...
2019-04-06 14:21:31 420
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人