上一页 1 2 3 4 5 6 7 ··· 10 下一页
摘要: /* 题目: 将字符串的前sep个字符转移到字符串尾部。 */ /* 思路: 更好的方法: 先翻转前sep个字符,再翻转后面的字符,最后全体翻转。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> 阅读全文
posted @ 2019-12-27 20:58 笨宝宝 阅读(153) 评论(0) 推荐(0)
摘要: /* 题目: 输入一个英文句子,翻转单词顺序,但单词内部顺序不变。 */ /* 思路: 先翻转整个句子,再将每个单词分别翻转一次。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #includ 阅读全文
posted @ 2019-12-27 20:40 笨宝宝 阅读(113) 评论(0) 推荐(0)
摘要: /* 题目: 输入一个整数s,输出所有和为s的连续整数序列。 */ /* 思路: 穷举法。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespa 阅读全文
posted @ 2019-12-27 17:45 笨宝宝 阅读(307) 评论(0) 推荐(0)
摘要: /* 题目: 输入一个递增数组和一个s,求和等于s的两个数组中的数字。 */ /* 思路: 双指针问题。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using 阅读全文
posted @ 2019-12-27 17:15 笨宝宝 阅读(142) 评论(0) 推荐(0)
摘要: /* 题目: 数组中除一个数字只出现一次外,其余数字都出现3次。 */ /* 思路: 位运算。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using names 阅读全文
posted @ 2019-12-27 16:56 笨宝宝 阅读(175) 评论(0) 推荐(0)
摘要: /* 题目: 求数组A中只出现一次的数字,该数组中有2个数字a、b仅出现一次,其余均出现两次 */ /* 思路: 两个相同的数字异或为0. 遍历数组,得到数组中各数字异或后的结果x,结果x=a^b。 x中肯定存在一位不为0,找到左起第一位为1的位。 根据该位,将数组分为两拨,再进行异或,得到的结果即 阅读全文
posted @ 2019-12-25 18:02 笨宝宝 阅读(150) 评论(0) 推荐(0)
摘要: /* 题目: 判断二叉树是否为平衡二叉树。 */ /* 思路: 判断二叉树的左子树和右子树高度相差是否为1. */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> usin 阅读全文
posted @ 2019-12-25 17:07 笨宝宝 阅读(169) 评论(0) 推荐(0)
摘要: /* 题目: 二叉树的深度 */ /* 思路: 根节点高度(0或1)+左子树的深度+右子树的深度 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using name 阅读全文
posted @ 2019-12-25 16:10 笨宝宝 阅读(105) 评论(0) 推荐(0)
摘要: /* 题目: 求二叉搜索树的第k大节点。 */ /* 思路: 中序遍历。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace std; s 阅读全文
posted @ 2019-12-23 22:24 笨宝宝 阅读(241) 评论(0) 推荐(0)
摘要: /* 题目: 求单调递增数组中,数值与下标相等的任意数字。 */ /* 思路: 二分法。 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespac 阅读全文
posted @ 2019-12-23 21:45 笨宝宝 阅读(134) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 ··· 10 下一页