摘要: 题目: Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to  阅读全文
posted @ 2016-06-07 15:29 沧浪少年 阅读(428) 评论(0) 推荐(0) 编辑
摘要: 题目: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should return 阅读全文
posted @ 2016-06-03 22:25 沧浪少年 阅读(908) 评论(0) 推荐(0) 编辑
摘要: 题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique 阅读全文
posted @ 2016-06-03 17:01 沧浪少年 阅读(575) 评论(0) 推荐(0) 编辑
摘要: 题目: 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 阅读全文
posted @ 2016-06-03 16:26 沧浪少年 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 题目要求: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. 给出一棵二叉树,其中有两个结点交换了位置,要求找出这两个 阅读全文
posted @ 2016-06-03 15:52 沧浪少年 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 树节点定义: 递归建立二叉树: 1、先序遍历 遍历方式:根节点-->左节点-->右节点 递归先序遍历: 非递归遍历: 对于任意一个结点p 1)访问结点p,并将p入栈 2)将p变为p的左孩子结点,如果p的不为空,循环至 1); 否则弹出当前栈顶使用p接收,将p变为p的右孩子结点; 3)当p结点为nul 阅读全文
posted @ 2016-06-02 18:01 沧浪少年 阅读(392) 评论(0) 推荐(0) 编辑
摘要: 题目要求: * 给定字符串,求解最长回文子串 * 字符串最长为1000 * 存在独一无二的最长回文字符串 求解思路: * 回文字符串的子串也是回文,比如P[i,j](表示以i开始以j结束的子串)是回文字符串, * 那么P[i+1,j-1]也是回文字符串。这样最长回文子串就能分解成一系列子问题了。 * 阅读全文
posted @ 2016-05-31 17:26 沧浪少年 阅读(1777) 评论(0) 推荐(0) 编辑
摘要: 题目需求: 输入一个字符串,输出对应的int值 特殊处理: 输入: null 输出:0 输入: "a122" 输出:0 输入: " 1233" 输出:1233 输入: " -123" 输出:-123 输入: "+123" 输出:123 输入: " 123a233" 输出:123 输入: "-123 阅读全文
posted @ 2016-05-31 15:51 沧浪少年 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity 思路1: 依次归并排序,首先归并前两个,然后归并完成的链表依次和剩下的链表进行归并排序 时间复杂 阅读全文
posted @ 2016-05-30 20:17 沧浪少年 阅读(573) 评论(0) 推荐(0) 编辑
摘要: 题目要求: Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' valu 阅读全文
posted @ 2016-05-28 11:59 沧浪少年 阅读(915) 评论(0) 推荐(0) 编辑