- 博客(77)
- 资源 (3)
- 收藏
- 关注
原创 进制转换
题目描述写出一个程序,接受一个十六进制的数值字符串,输出该数值的十进制字符串。(多组同时输入 )输入描述:输入一个十六进制的数值字符串。输出描述:输出该数值的十进制字符串。输入例子:0xA输出例子:10#include #include #include using namespace std;int main()
2016-05-07 20:47:58
318
转载 Morgan IT 笔试面试汇总
Morgan Stanley IT笔试题部分回忆版笔试,Stanley特点:1. 题量大,43页的卷子,厚厚一摞,直接把我砸晕了。。2. 全英文题目,全英文作答,监考人员强调,千万别写中文哦,改卷子的人看不懂滴~所以,学好英语很重要很重要,我后面答题的时候居然N多单词8会写… 3. 题目很杂,什么都有,Java,C++,C#,数据库,操作系统,网络,还有包括SMTP,I
2016-04-16 01:59:55
2426
原创 复杂链表的复制
题目描述输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点)。/*struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode(int x) : label(x), nex
2016-04-13 20:21:08
505
原创 二叉树中和为某一值的路径
题目描述输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL)
2016-04-13 17:37:48
387
原创 二叉搜索树与双向链表
题目描述输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL)
2016-04-12 21:34:56
277
原创 栈的压入、弹出序列
题目描述输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。class Solution {public: stack s1; bool IsPopOrder
2016-04-12 13:15:15
228
原创 顺时针打印矩阵
题目描述输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10.class Solution {public: vector printMatrix(vector > mat
2016-04-12 01:14:45
221
原创 二叉搜索树的后序遍历序列
题目描述输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。class Solution {public: bool c(vector s,int low,int high) { int key=s[high]; int i=high-1;
2016-04-11 21:29:30
199
原创 从上往下打印二叉树
题目描述从上往下打印出二叉树的每个节点,同层节点从左至右打印。/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {pu
2016-04-11 21:01:13
267
原创 字符串的排列
题目描述输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。 结果请按字母顺序输出。 输入描述:输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。class Solution {public: void p(string s
2016-04-11 16:13:50
213
原创 数组中出现次数超过一半的数字
题目描述数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}。由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2。如果不存在则输出0。class Solution {public: int MoreThanHalfNum_Solution(vector numbers) {
2016-04-11 15:16:50
273
原创 把数组排成最小的数
题目描述输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323。class Solution {public: static bool cmp(string a,string b) { if(a+b<b+a)
2016-04-11 10:31:25
216
原创 第一个只出现一次的字符位置
题目描述在一个字符串(1class Solution {public: int FirstNotRepeatingChar(string str) { map m; int n=str.length(); if(n<=0) return -1; for(int i=0;i<n;+
2016-04-11 09:07:01
208
原创 和为S的连续正数序列
题目描述小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100。但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数)。没多久,他就得到另一组连续正数和为100的序列:18,19,20,21,22。现在把问题交给你,你能不能也很快的找出所有和为S的连续正数序列? Good Luck! 输出描述:输出所有和为S的连续
2016-04-11 09:00:58
254
原创 左旋转字符串
题目描述汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果。对于一个给定的字符序列S,请你把其循环左移K位后的序列输出。例如,字符序列S=”abcXYZdef”,要求输出循环左移3位后的结果,即“XYZdefabc”。是不是很简单?OK,搞定它!class Solution {public: string LeftRotat
2016-04-11 08:15:23
207
原创 翻转单词顺序列
题目描述牛客最近来了一个新员工Fish,每天早晨总是会拿着一本英文杂志,写些句子在本子上。同事Cat对Fish写的内容颇感兴趣,有一天他向Fish借来翻看,但却读不懂它的意思。例如,“student. a am I”。后来才意识到,这家伙原来把句子单词的顺序翻转了,正确的句子应该是“I am a student.”。Cat对一一的翻转这些单词顺序可不在行,你能帮助他么?class So
2016-04-11 08:03:56
278
原创 扑克牌顺子
题目描述LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决定去买体育彩票,嘿嘿!!“红心A,黑桃3,小王,大王,方片5”,“Oh My God!”不是顺子.....LL不高兴了,他想了想,决定大\小 王可以看成任何数字,并且A看作1,J为11,Q为12
2016-04-10 22:21:44
255
原创 孩子们的游戏(圆圈中最后剩下的数)
题目描述每年六一儿童节,NowCoder都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此。HF作为NowCoder的资深元老,自然也准备了一些小游戏。其中,有个游戏是这样的:首先,让小朋友们围成一个大圈。然后,他随机指定一个数m,让编号为0的小朋友开始报数。每次喊到m的那个小朋友要出列唱首歌,然后可以在礼品箱中任意的挑选礼物,并且不再回到圈中,从他的下一个小朋友开始,继续0...m-1
2016-04-10 19:33:45
236
原创 把字符串转换成整数
题目描述将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数。class Solution {public: int ctoi(char c) { if(c='0') return c-'0'; return 0; } int nu(int n) { i
2016-04-10 18:36:11
228
原创 正则表达式匹配
题目描述请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"ab*ac*a"匹配,但是与"aa.a"和"ab*a"均不匹配class Solution {public: bool c(char*
2016-04-10 17:58:52
217
原创 表示数值的字符串
题目描述请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。class Solution {public: bool num(char c) { if(c='
2016-04-10 15:37:20
206
原创 链表中环的入口结点
题目描述一个链表中包含环,请找出该链表的环的入口结点。/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class Solution {public: ListNode* Entr
2016-04-10 15:04:38
193
原创 删除链表中重复的结点
题目描述在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(
2016-04-10 14:38:16
201
原创 二叉树的下一个结点
题目描述给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。using namespace std;/*struct TreeLinkNode { int val; struct TreeLinkNode *left; struct TreeLinkNode *right;
2016-04-10 11:14:30
218
原创 按之字形顺序打印二叉树
题目描述请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推。/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) :
2016-04-10 10:31:47
207
原创 丑数
题目描述把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。class Solution {public: int min2(int a,int b,int c) { int min1=std::min(a,b);
2016-04-10 09:32:02
223
原创 数组中只出现一次的数字
题目描述一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。class Solution {public: void FindNumsAppearOnce(vector data,int* num1,int *num2) { int temp=0; int size=data.size();
2016-04-09 20:31:03
216
原创 225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet
2016-03-14 21:46:21
196
原创 278. First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the
2016-03-09 20:57:05
192
原创 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get
2016-03-09 20:19:59
209
原创 189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].class Solution {public: void rotate(vector&
2016-03-09 19:14:12
194
原创 165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2016-03-09 18:51:56
168
原创 8. String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca
2016-03-09 16:17:00
240
原创 110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
2016-03-02 23:49:01
213
原创 232. Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(
2016-02-28 01:03:09
210
原创 21. Merge Two Sorted Lists
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./** * Definition for singly-linked list. * struct ListN
2016-02-27 08:14:33
177
原创 326. Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?class Solution {public: bool isPowerOfThree(int n) {
2016-02-27 00:59:35
187
原创 202. Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares
2016-02-27 00:42:18
193
原创 70. Climbing Stairs
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 the top?class Solution {public: int
2016-02-27 00:09:27
199
原创 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2016-02-26 23:51:56
190
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人