
笔试
槿梓
杂学的电气信息工人
展开
-
LeetCode——三数之和+三数最接近之和+四数之和
看到很多人的题目答案没有注释,在程序详细标注了一下。解题思路是:排序(快排)+双指针+移动去重。 class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { sort(nums.begin(),nums.end()); //快速...原创 2019-06-04 15:56:33 · 448 阅读 · 0 评论 -
斐波那切数列之动态规划
剑指offer:大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。n&amp;amp;amp;amp;amp;amp;amp;lt;=39 做到这个题,初学者可能会难以理解迭代法的思路;本人觉得加入以下注释后,可以帮助理解; class Solution { public: int Fibonacci(int n) { //采用迭代法 int f=0,g=1;/...原创 2019-03-14 23:00:10 · 544 阅读 · 0 评论 -
剑指offer——序列化二叉树
题目:请实现两个函数,分别用来序列化和反序列化二叉树 序列化:得到层序序列 10,20,30,4,#,#,5,6,#,#,#,#,#,7,#, 发序列化:重建二叉树。 class Solution { public: char* Serialize(TreeNode *root) { if(root == NULL) return NULL; ...原创 2019-04-19 18:19:20 · 238 阅读 · 0 评论 -
腾讯2017——求相差最小和相差最大的对数
腾讯2017笔试题:小Q今天在上厕所时想到了这个问题:有n个数,两两组成二元组,相差最小的有多少对呢?相差最大呢? #include&lt;iostream&gt; #include&lt;vector&gt; #include&lt;algorithm&gt; using namespace std; int main() { int n; while (cin &gt;&原创 2019-03-12 21:20:48 · 680 阅读 · 0 评论 -
腾讯2017——字符串的大写字母放到后面
腾讯2017笔试题:把一个字符串的大写字母放到字符串的后面,各个字符的相对位置不变,且不能申请额外的空间。 #include"iostream" #include"string.h" using namespace std; int main() { string str1;//存放输入的字符串 while(cin&gt;&gt;str1) { int i=...原创 2019-03-12 21:27:17 · 475 阅读 · 0 评论