摘要:
1.直接把递归把左右子树翻转即可AC代码:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tr... 阅读全文
posted @ 2015-11-20 22:20
siukwan
阅读(122)
评论(0)
推荐(0)
摘要:
1.和leetcode中的Invert Binary Tree(easy)题目差不多2.利用递归函数,每次都把左右子树翻转即可函数如下:void invertTree(TreeNode* root){ if (root != NULL) { swap(root->l, root->r); inv... 阅读全文
posted @ 2015-11-20 22:15
siukwan
阅读(133)
评论(0)
推荐(0)
摘要:
1.这道题目需要考虑采用适当的数据结构,即小根堆和大根堆2.判断某个元素是否能够成为pivot,那么该元素左边数组应该构成一个大根堆,堆顶元素应该小于该元素,该元素的右边构成小根堆,堆顶元素大于该元素3.左边的小根堆,一直插入即可,利用priority_queue,而右边则需要进行维护,需要编写仿函... 阅读全文
posted @ 2015-11-20 21:33
siukwan
阅读(170)
评论(0)
推荐(0)
摘要:
1.这个和最长公共子序列问题相类似(LCS)2.不同的地方是允许元素重复,如{a}和{aaa},匹配出来的是3,a可以重复3次3.该问题一开始卡在了输入格式上4.动态规划方程:dp[i][j]表示f[0~i]与o[0~j]匹配的最大长度如果f[i]==o[j],dp[i][j]=max(dp[i][... 阅读全文
posted @ 2015-11-20 20:32
siukwan
阅读(146)
评论(0)
推荐(0)
摘要:
1.十进制与13进制之间的转换2.注意输入为13,26,39整数时,只输出一个marsNum,后面低位的0不输出AC代码://#include//#include #include#include //#include#include#include#include//#include#includ... 阅读全文
posted @ 2015-11-20 16:23
siukwan
阅读(174)
评论(0)
推荐(0)
摘要:
1.这道题需要注意,s1和s2的输入都需要使用getline,避免出现空格的情况AC代码://#include//#include #include#include //#include#include#include#include//#include#include//#include //#i... 阅读全文
posted @ 2015-11-20 14:54
siukwan
阅读(115)
评论(0)
推荐(0)
摘要:
1.算法说明:如3141592,在m(digitDivide)=100时,即要求计算百位上“1”的个数其中a为31415,b为92,31415中出现了3142次“1”,因为每10个数里面出现1次“1”。而实际上,31415是3141500,所以把31415中1的个数再乘以m。如3141400~314... 阅读全文
posted @ 2015-11-20 14:53
siukwan
阅读(155)
评论(0)
推荐(0)
摘要:
1.和leetcode里面的Number of Digit One一样2.算法说明:如3141592,在m(digitDivide)=100时,即要求计算百位上“1”的个数其中a为31415,b为92,31415中出现了3142次“1”,因为每10个数里面出现1次“1”。而实际上,31415是314... 阅读全文
posted @ 2015-11-20 14:48
siukwan
阅读(134)
评论(0)
推荐(0)
摘要:
1.遍历一次nums,利用map记录已经遍历过的nums[i],并记录其index :i+12.每次求出b=target-nums[i],检测b是否在map中,如果在,则已经得到答案,否则,把nums[i]存到map里面AC代码:class Solution {public: vector t... 阅读全文
posted @ 2015-11-20 14:46
siukwan
阅读(105)
评论(0)
推荐(0)
摘要:
1.和前面的1039 Course List for Student (25)相类似2.刚开始使用vector> 格式存储course,后面在输入数据的时候就已经超时3.随后改为vector> 存储,在后面进行sort,没有超时AC代码如下://#include//#include #include... 阅读全文
posted @ 2015-11-20 13:45
siukwan
阅读(142)
评论(0)
推荐(0)
摘要:
1.建立一个数组dp[i],记录0到i之间的距离和2.定义sum,记录全程的路程和3.求i,j的最短距离时,利用ans=dp[j]-[i]+num[i]-num[j],ans2=sum-ans,min(ans,ans2)即为答案AC代码:#include #include #include #inc... 阅读全文
posted @ 2015-11-20 00:06
siukwan
阅读(158)
评论(0)
推荐(0)

浙公网安备 33010602011771号