剑指offer 二叉搜索树与双向链表
2016-03-16 21:02
507 查看
html, body {
font-size: 15px;
}
body {
font-family: Helvetica, "Hiragino Sans GB", 微软雅黑, "Microsoft YaHei UI", SimSun, SimHei, arial, sans-serif;
line-height: 1.6;
color: ;
background-color: ;
margin: 0;
padding: 16px 20px;
}
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
margin: 1.33rem 0 0.667rem;
padding: 0;
font-weight: bold;
}
h1 {
font-size: 21px;
font-size: 1.4rem;
}
h2 {
font-size: 20px;
font-size: 1.33rem;
}
h3 {
font-size: 18px;
font-size: 1.2rem;
}
h4 {
font-size: 17px;
font-size: 1.13rem;
}
h5 {
font-size: 15px;
font-size: 1rem;
}
h6 {
font-size: 15px;
font-size: 1rem;
color: #777777;
margin: 1rem 0;
}
div, p, ul, ol, dl, li {
margin: 0;
}
blockquote, table, pre, code{
margin: 8px 0;
}
ul, ol {
padding-left: 32px;
padding-left: 2.13rem;
}
blockquote {
border-left: 4px solid #dddddd;
padding: 0 12px;
padding: 0 0.8rem;
}
blockquote > :first-child {
margin-top: 0;
}
blockquote > :last-child {
margin-bottom: 0;
}
img {
border: 0;
max-width: 100%;
height: auto !important;
margin: 2px 0;
}
table {
border-collapse: collapse;
border: 1px solid #bbbbbb;
}
td {
padding:4px 8px;
border-collapse: collapse;
border: 1px solid #bbbbbb;
}
@media screen and (max-width: 660px) {
body {
padding: 20px 18px;
padding: 1.33rem 1.2rem;
}
}
@media only screen and (-webkit-max-device-width: 1024px), only screen and (-o-max-device-width: 1024px), only screen and (max-device-width: 1024px), only screen and (-webkit-min-device-pixel-ratio: 3), only screen and (-o-min-device-pixel-ratio: 3), only screen and (min-device-pixel-ratio: 3) {
html, body {
font-size: 17px;
}
body {
line-height: 1.7;
padding: 0.75rem 0.9375rem;
color: #353c47;
}
h1 {
font-size: 2.125rem;
}
h2 {
font-size: 1.875rem;
}
h3 {
font-size: 1.625rem;
}
h4 {
font-size: 1.375rem;
}
h5 {
font-size: 1.125rem;
}
h6 {
color: inherit;
}
ul, ol {
padding-left: 2.5rem;
}
blockquote {
padding: 0 0.9375rem;
}
}
剑指offer 二叉搜索树与双向链表
输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。
![](http://images2015.cnblogs.com/blog/567993/201603/567993-20160316210126084-1731513608.png)
思路,中序遍历压入vector,然后调整
font-size: 15px;
}
body {
font-family: Helvetica, "Hiragino Sans GB", 微软雅黑, "Microsoft YaHei UI", SimSun, SimHei, arial, sans-serif;
line-height: 1.6;
color: ;
background-color: ;
margin: 0;
padding: 16px 20px;
}
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
margin: 1.33rem 0 0.667rem;
padding: 0;
font-weight: bold;
}
h1 {
font-size: 21px;
font-size: 1.4rem;
}
h2 {
font-size: 20px;
font-size: 1.33rem;
}
h3 {
font-size: 18px;
font-size: 1.2rem;
}
h4 {
font-size: 17px;
font-size: 1.13rem;
}
h5 {
font-size: 15px;
font-size: 1rem;
}
h6 {
font-size: 15px;
font-size: 1rem;
color: #777777;
margin: 1rem 0;
}
div, p, ul, ol, dl, li {
margin: 0;
}
blockquote, table, pre, code{
margin: 8px 0;
}
ul, ol {
padding-left: 32px;
padding-left: 2.13rem;
}
blockquote {
border-left: 4px solid #dddddd;
padding: 0 12px;
padding: 0 0.8rem;
}
blockquote > :first-child {
margin-top: 0;
}
blockquote > :last-child {
margin-bottom: 0;
}
img {
border: 0;
max-width: 100%;
height: auto !important;
margin: 2px 0;
}
table {
border-collapse: collapse;
border: 1px solid #bbbbbb;
}
td {
padding:4px 8px;
border-collapse: collapse;
border: 1px solid #bbbbbb;
}
@media screen and (max-width: 660px) {
body {
padding: 20px 18px;
padding: 1.33rem 1.2rem;
}
}
@media only screen and (-webkit-max-device-width: 1024px), only screen and (-o-max-device-width: 1024px), only screen and (max-device-width: 1024px), only screen and (-webkit-min-device-pixel-ratio: 3), only screen and (-o-min-device-pixel-ratio: 3), only screen and (min-device-pixel-ratio: 3) {
html, body {
font-size: 17px;
}
body {
line-height: 1.7;
padding: 0.75rem 0.9375rem;
color: #353c47;
}
h1 {
font-size: 2.125rem;
}
h2 {
font-size: 1.875rem;
}
h3 {
font-size: 1.625rem;
}
h4 {
font-size: 1.375rem;
}
h5 {
font-size: 1.125rem;
}
h6 {
color: inherit;
}
ul, ol {
padding-left: 2.5rem;
}
blockquote {
padding: 0 0.9375rem;
}
}
剑指offer 二叉搜索树与双向链表
输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。
![](http://images2015.cnblogs.com/blog/567993/201603/567993-20160316210126084-1731513608.png)
思路,中序遍历压入vector,然后调整
12345678910111213141516171819202122232425262728293031323334 | /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } }; */ class Solution { public : vector<TreeNode *> m_vector; TreeNode* Convert(TreeNode* pRootOfTree) { if (pRootOfTree==NULL) return NULL; printVector(pRootOfTree); for ( int i= 0 ;i<m_vector.size()- 1 ;i++) { m_vector[i]->right=m_vector[i+ 1 ]; m_vector[i+ 1 ]->left=m_vector[i]; } return m_vector[ 0 ]; } void printVector(TreeNode *root) { if (root->left!=NULL) printVector(root->left); m_vector.push_back(root); if (root->right!=NULL) printVector(root->right); } }; |
相关文章推荐
- 剑指offer 连续子序列和
- 剑指offer 整数中1 出现的次数
- 第七章:JavaScript面向对象三大特征
- 每日一bootstrap 表单
- 剑指offer 和为S的两个数字
- 剑指offer 判断树是不是对称的
- jQuery EasyUI中常常遇到的问题(FAQ)
- js笔记
- 【优化】前端优化的几种常用方法(持续更新)
- 剑指offer之有序二维数组查找
- 在html <table> 标签的中background和bgcolor两个属性有什么关系?
- 滚动监听导航 JQUERY 易懂
- JSP初学
- javascript 关于弹出新页面始终在正中央方法
- CSS中box-reflect特性以及火狐浏览器替代方案
- js调用百度地图API
- JavaScript中的引用类型
- Zox's code life 人生就是不停的战斗! xxx is not in the sudoers file.This incident will be reported.的解决方法
- 剑指offer 数字在排序数组中出现的次数
- 剑指offer 数组中只出现一次的数字