
C++
Seazzy5461
这个作者很懒,什么都没留下…
展开
-
LeetCode——二叉树的所有路径
给定一个二叉树,返回所有从根节点到叶子节点的路径。说明: 叶子节点是指没有子节点的节点。示例:输入: 1 / \2 3 \ 5输出: ["1->2->5", "1->3"]解释: 所有根节点到叶子节点的路径为: 1->2->5, 1->3DFS,分为递归和迭代两种方法递归/** * Definition...原创 2019-05-20 09:54:22 · 637 阅读 · 0 评论 -
c++删除vector容器中重复元素
vector<int> v={1,2,4,3,5.2};则调用以下语句即可:sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());原创 2018-08-30 15:43:26 · 4023 阅读 · 0 评论 -
网易校招真题——小易喜欢的单词
牛客网编程题——小易喜欢的单词题目描述 小易喜欢的单词具有以下特性: 1.单词每个字母都是大写字母 2.单词没有连续相等的字母 3.单词没有形如“xyxy”(这里的x,y指的都是字母,并且可以相同)这样的子序列,子序列可能不连续。 例如: 小易不喜欢”ABBA”,因为这里有两个连续的’B’ 小易不喜欢”THETXH”,因为这里包含子序列”THTH” 小易...原创 2018-08-30 10:34:28 · 641 阅读 · 0 评论 -
网易校招真题——暗黑的字符串
题目描述 一个只包含’A’、’B’和’C’的字符串,如果存在某一段长度为3的连续子串中恰好’A’、’B’和’C’各有一个,那么这个字符串就是纯净的,否则这个字符串就是暗黑的。例如: BAACAACCBAAA 连续子串”CBA”中包含了’A’,’B’,’C’各一个,所以是纯净的字符串 AABBCCAABB 不存在一个长度为3的连续子串包含’A’,’B’,’C’,所以是暗黑的...原创 2018-09-04 19:30:44 · 207 阅读 · 0 评论 -
网易校招真题——两种排序方法
牛客编程题——两种排序方法题目描述 考拉有n个字符串字符串,任意两个字符串长度都是不同的。考拉最近学习到有两种字符串的排序方法: 1.根据字符串的字典序排序。例如: “car”&lt; “carriage” &lt; “cats” &lt; “doggies &lt; “koala” 2.根据字符串的长度排序。例如: “car” &lt; “cats” &lt; “koa...原创 2018-08-29 09:45:51 · 337 阅读 · 0 评论 -
网易校招真题——饥饿的小易
牛客网编程题——饥饿的小易题目描述 小易总是感觉饥饿,所以作为章鱼的小易经常出去寻找贝壳吃。最开始小易在一个初始位置x_0。对于小易所处的当前位置x,他只能通过神秘的力量移动到 4 * x + 3或者8 * x + 7。因为使用神秘力量要耗费太多体力,所以它只能使用神秘力量最多100,000次。贝壳总生长在能被1,000,000,007整除的位置(比如:位置0,位置1,00...原创 2018-08-28 19:23:18 · 592 阅读 · 0 评论 -
今日头条校招真题——字典序
牛客网编程题——字典序题目描述 给定整数n和m, 将1到n的这n个整数按字典序排列之后, 求其中的第m个数。 对于n=11, m=4, 按字典序排列依次为1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9, 因此第4个数是2. 对于n=200, m=25, 按字典序排列依次为1 10 100 101 102 103 104 105 106 107 108 ...原创 2018-08-24 11:23:02 · 547 阅读 · 0 评论 -
网易校招真题——洗牌
牛客校招真题——洗牌题目描述 洗牌在生活中十分常见,现在需要写一个程序模拟洗牌的过程。 现在需要洗2n张牌,从上到下依次是第1张,第2张,第3张一直到第2n张。首先,我们把这2n张牌分成两堆,左手拿着第1张到第n张(上半堆),右手拿着第n+1张到第2n张(下半堆)。接着就开始洗牌的过程,先放下右手的最后一张牌,再放下左手的最后一张牌,接着放下右手的倒数第二张牌,再放下左手的倒数第...原创 2018-08-31 11:24:14 · 370 阅读 · 0 评论 -
今日头条校招真题——异或
牛客网编程题——异或题目描述 给定整数m以及n各数字A1,A2,..An,将数列A中所有元素两两异或,共能得到n(n-1)/2个结果,请求出这些结果中大于m的有多少个。输入描述 第一行包含两个整数n,m. 第二行给出n个整数A1,A2,…,An。 数据范围 对于30%的数据,1 &lt;= n, m &lt;= 1000 对于10...原创 2018-08-23 11:26:32 · 616 阅读 · 0 评论 -
今日头条校招真题——头条校招
牛客网编程题——头条校招题目描述 头条的2017校招开始了!为了这次校招,我们组织了一个规模宏大的出题团队,每个出题人都出了一些有趣的题目,而我们现在想把这些题目组合成若干场考试出来,在选题之前,我们对题目进行了盲审,并定出了每道题的难度系统。一场考试包含3道开放性题目,假设他们的难度从小到大分别为a,b,c,我们希望这3道题能满足下列条件: a&lt;=b&lt;=c b-a&lt;=...原创 2018-08-22 17:54:53 · 524 阅读 · 0 评论 -
360校招真题——最强大脑
牛客网编程题——最强大脑题目描述 小B乘火车和朋友们一起在N市到M市之间旅行。她在路途中时睡时醒。当她醒来观看窗外的风景时,注意到每个火车站都有一种特别颜色的旗帜,但是她看到的旗帜仅仅是经过的一小部分。小B在乘车过程中有两次清醒的时间,她到达旅程终点时处于睡梦中。出站时,她和朋友们谈论着一路的见闻,朋友们觉得很有意思,他们把N到和M之间经过车站的旗帜颜色依次列出来,然后告诉你小B记得的...原创 2018-08-22 11:43:31 · 897 阅读 · 0 评论 -
网易校招真题——数字游戏
网易笔试题——数字游戏题目描述 小易邀请你玩一个数字游戏,小易给你一系列的整数。你们俩使用这些整数玩游戏。每次小易会任意说一个数字出来,然后你需要从这一系列数字中选取一部分出来让它们的和等于小易所说的数字。 例如: 如果{2,1,2,7}是你有的一系列数,小易说的数字是11.你可以得到方案2+2+7 = 11.如果顽皮的小易想坑你,他说的数字是6,那么你没有办法拼凑出和为6...原创 2018-08-30 15:53:56 · 298 阅读 · 0 评论 -
C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的区别
1、cin 2、cin.get() 3、cin.getline() 4、getline() 5、gets() 6、getchar()附:cin.ignore();cin.get()//跳过一个字符,例如不想要的回车,空格等字符1、cin>>用法1:最基本,也是最常用的用法,输入一个数字:#include <iostream> usi...原创 2018-09-08 14:24:25 · 449 阅读 · 0 评论 -
LeetCode——反转链表
反转一个单链表。示例:输入: 1->2->3->4->5->NULL输出: 5->4->3->2->1->NULL进阶:你可以迭代或递归地反转链表。你能否用两种方法解决这道题?C++迭代做法/** * Definition for singly-linked list. * struct ListNode { ...原创 2019-05-13 17:44:11 · 294 阅读 · 0 评论 -
网易校招——藏宝图
题目描述牛牛拿到了一个藏宝图,顺着藏宝图的指示,牛牛发现了一个藏宝盒,藏宝盒上有一个机关,机关每次会显示两个字符串 s 和 t,根据古老的传说,牛牛需要每次都回答 t 是否是 s 的子序列。注意,子序列不要求在原字符串中是连续的,例如串 abc,它的子序列就有{空串, a, b, c, ab, ac, bc, abc} 8 种。输入描述:每个输入包含一个测试用例。每个测试用例包含两行长...原创 2018-10-17 15:09:19 · 511 阅读 · 0 评论 -
网易校招真题——下厨房
题目描述 牛牛想尝试一些新的料理,每个料理需要一些不同的材料,问完成所有的料理需要准备多少种不同的材料。输入描述: 每个输入包含 1 个测试用例。每个测试用例的第 i 行,表示完成第 i 件料理需要哪些材料,各个材料用空格隔开,输入只包含大写英文字母和空格,输入文件不超过 50 行,每一行不超过 50 个字符。输出描述: 输出一行一个数字表示完成所有料理需...原创 2018-09-07 15:54:47 · 321 阅读 · 0 评论 -
使用位运算实现加减乘除
在不使用+,-,*,/,四则运算符号的情况下,通过基本位运算实现加减乘除四则运算。1. C++中使用位运算实现加法首先,我们通过对x和y进行&位运算,得出每一位上的进位。然后对x和y进行^位运算,得出没有加进位的和。最后将所得的和当做新的x,所得的进位往左移一位(第零位的进位输入为0)当做新的y,继续做上面的步骤,直到进位为0,此时x中保存的就是我们要求的x和y的和了。 ...原创 2018-09-12 11:43:59 · 1604 阅读 · 0 评论 -
剑指offer——数组中只出现一次的数字
题目描述一个整型数组里除了两个数字之外,其他的数字都出现了偶数次。请写程序找出这两个只出现一次的数字。两种方法,一种简单,一种秀肌肉。第一种代码如下,就用一个count函数。class Solution {public: void FindNumsAppearOnce(vector&lt;int&gt; data,int* num1,int *num2) { ...原创 2018-09-12 10:18:02 · 238 阅读 · 0 评论 -
sublime text3编译C++,C
打开sublime text3,依次: tools-&amp;gt;building system-&amp;gt;new building system复制粘贴以下内容{ &quot;shell_cmd&quot;: &quot;g++ \&quot;${file}\&quot; -o \&quot;${file_path}/${file_base_name}原创 2018-09-06 09:23:15 · 567 阅读 · 0 评论 -
网易校招真题——回文序列
牛客校招真题——回文序列题目描述 如果一个数字序列逆置之后跟原序列是一样的就称这样的数字序列为回文序列。例如: {1, 2, 1}, {15, 78, 78, 15} , {112} 是回文序列, {1, 2, 2}, {15, 78, 87, 51} ,{112, 2, 11} 不是回文序列。 现在给出一个数字序列,允许使用一种转换操作: 选择任意两个相邻的数,然...原创 2018-09-03 16:24:57 · 388 阅读 · 0 评论 -
网易校招真题——构造队列
题目描述小明同学把1到n这n个数字按照一定的顺序放入了一个队列Q中。现在他对队列Q执行了如下程序:while(!Q.empty()) //队列不空,执行循环{ int x=Q.front(); //取出当前队头的值x Q.pop(); //弹出当前队头 Q.push(x);...原创 2018-09-03 11:02:14 · 276 阅读 · 0 评论 -
滴滴校招真题——末尾0的个数
题目描述 输入一个正整数n,求n!(即阶乘)末尾有多少个0? 比如: n = 10; n! = 3628800,所以答案为2输入描述: 输入为一行,n(1 ≤ n ≤ 1000)输出描述: 输出一个整数,即题目所求示例1 输入 10 输出其实就是求到n的数中,有多少数是包含因数5,总共包含了多少因数5。 解释:比如100/...原创 2018-09-08 16:48:22 · 556 阅读 · 0 评论 -
c++输出小数点后位数精度
头文件#include<iomanip>,函数setprecision()setprecision(n) 指定一个浮点数的精度默认设置输出的数字的总位数为n,包含整数和小数部分。fixed :必须与setprecision(n)配合使用,用来控制小数位数,不够补0,只要写一次fixed,后面的setprecision(n)就都是指小数了。如果不使用fixed,setprec...原创 2018-09-08 15:11:42 · 9397 阅读 · 0 评论 -
网易校招真题——合唱团
牛客网编程题——合唱团 题目描述 有 n 个学生站成一排,每个学生有一个能力值,牛牛想从这 n 个学生中按照顺序选取 k 名学生,要求相邻两个学生的位置编号的差不超过 d,使得这 k 个学生的能力值的乘积最大,你能返回最大的乘积吗? 输入描述: 每个输入包含 1 个测试用例。每个测试数据的第一行包含一个整数 n (1 &lt;= n ...原创 2018-08-04 19:59:11 · 327 阅读 · 0 评论 -
LeetCode——Reverse Integer
LeetCode——Reverse Integer # 7 Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input:...原创 2018-02-25 16:04:41 · 175 阅读 · 0 评论 -
LeetCode——Best Time to Buy and Sell Stock
LeetCode——Best Time to Buy and Sell Stock # 121 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one t原创 2017-11-18 22:39:00 · 276 阅读 · 0 评论 -
LeetCode——Subtree of Another
LeetCode——Subtree of Another Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a原创 2017-11-12 23:06:08 · 269 阅读 · 0 评论 -
LeetCode——Maximum subarray
LeetCode——Maximum Subarray # 53 Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4],原创 2017-11-04 18:09:10 · 260 阅读 · 0 评论 -
LeetCode——Climbing Stairs
LeetCode——Climbing Stairs # 70 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to t原创 2017-11-01 22:32:12 · 255 阅读 · 0 评论 -
LeetCode——Merge Two Sorted Lists
LeetCode——Merge Two Sorted Lists #21 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.原创 2017-11-01 22:20:34 · 237 阅读 · 0 评论 -
LeetCode——Symmetric Tree
LeetCode——Symmetric Tree # 101 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric:原创 2017-11-09 22:42:31 · 253 阅读 · 0 评论 -
LeetCode——Single Numeber
LeetCode——Single Number # 136 Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Co原创 2017-11-07 21:47:08 · 236 阅读 · 0 评论 -
LeetCode——Valid Parenthese
Leetcode——Valid Parenthese #20 Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.原创 2017-10-29 19:11:08 · 427 阅读 · 0 评论 -
LeetCode——Two Sum
LeetCode——Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.原创 2017-10-29 11:47:03 · 570 阅读 · 0 评论 -
GCC编译时使用C++11standard
当使用GCC编译时如果代码中使用了C++11的标准,如果只用gcc -o就会提示错误。原创 2017-10-28 21:33:09 · 1904 阅读 · 0 评论 -
LeetCode——Linked List Cycle
LeetCode——Linked List Cycle #141 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 这一题的目的是判断链表中是否有环。一个思路是利用哈希表。如果遍历过的结点已经存在了原创 2017-11-19 21:43:28 · 225 阅读 · 0 评论 -
LeetCode——Maxium Depth of Binary Tree
LeetCode——Maxium Depth of Binary Tree # 104 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthes原创 2017-11-14 11:44:44 · 295 阅读 · 0 评论 -
LeetCode——Path Sum III
LeetCode——Path Sum III #437 You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to star原创 2017-11-27 19:52:37 · 328 阅读 · 0 评论 -
LeetCode——Move Zeroes
LeetCode——Move Zeroes #283 Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.for example, given nums = [0, 1,原创 2017-11-27 10:54:13 · 263 阅读 · 0 评论 -
LeetCode——Palindrome Linked List
LeetCode——Palindrome Linked List # 234 Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space?这一题的目的是判断一个单链表是否是回文链表,并且最好是在O(原创 2017-11-25 16:06:46 · 271 阅读 · 0 评论