刷刷刷刷题
wdf过河的小卒子
这个作者很懒,什么都没留下…
展开
-
华为机试-字符串的分割
#include<iostream>#include<string>#include<math.h>using namespace std;int main(){ string sInputString; char szOutputString[8]= {}; while(getline(cin, sInputString)) { int nL原创 2017-09-05 19:33:44 · 309 阅读 · 0 评论 -
包含min函数的栈
注意:题目不是实现一个栈,而是在栈的基础上实现一些操作class Solution {public: void push(int value) { st.push(value); if (smin.empty()) smin.push(value); if (smin.top() > value)原创 2018-01-21 16:25:48 · 214 阅读 · 0 评论 -
剑指-顺时针打印矩阵
注意:在每次进行循环进行读写时,一定要判断left、right、top、bom的关系 vectorint> printMatrix(vectorvectorint> > matrix) { vectorint> vecResult; if (matrix.size() == 0)return vecResult; int rowCoun原创 2018-01-21 16:01:44 · 238 阅读 · 0 评论 -
剑指-二叉树的镜像
注意此处:不要单独把左右子节点拿出来,会出错,目前还不知道原因 void Mirror(TreeNode *pRoot) { if (pRoot == NULL)return; TreeNode* temp; temp = pRoot->left; pRoot->left = pRoot->right; pRoot->right = temp;原创 2018-01-21 15:41:41 · 221 阅读 · 0 评论 -
剑指-二维数组中的查找
注意判断数组是否为空!!!bool Find(int target, vectorvectorint> > array) { if (array.empty())return false; int rowCount = array.size(); for (int i = 0; i < rowCount; i++) { if (array[原创 2018-01-21 14:39:53 · 220 阅读 · 0 评论 -
剑指-从尾到头打印链表
一定要看清楚题目是从尾到头打印链表!!! vectorint> printListFromTailToHead(ListNode* head) { vectorint> vec; if(head == NULL) { return vec; } ListNode* temp原创 2018-01-21 14:40:57 · 225 阅读 · 0 评论 -
剑指-利用树的前序遍历和中序遍历结果,输出树的原始结构
需要注意两点:1、对于前序遍历第一个即为根节点。2、在前序遍历找到根节点之后,在中序遍历中根节点之前的全部为根节点的左子树,后面的全部为右子树。所以可以根据中序遍历中根节点之前的数量,在前序遍历中找出左子树。3、递归实现就可以。TreeNode* reConstructBinaryTree(vector<int> pre, vector<int> vin) { int len = pre.原创 2018-01-21 14:39:00 · 278 阅读 · 0 评论 -
剑指offer-用两个栈实现一个队列
注意使用一个栈存储从头到尾的数据,然后利用该栈输出数据,同时使用另外一个栈存储从尾到头的数据。 void push(int node) { stack1.push(node); } int pop() { if (stack2.empty()) { while (!stack1.empty())原创 2018-01-21 14:37:24 · 154 阅读 · 0 评论 -
华为机试-坐标移动
#include<iostream>#include<string>#include<math.h>#include<vector>#include<map>#include<set>using namespace std;typedef struct point{ int posx; int posy;}pos;void SplitSting(const strin原创 2017-09-28 21:25:12 · 420 阅读 · 0 评论 -
华为机试-明明的随机数
#include<iostream>#include<string>using namespace std;int main(){ int randomNumberCount; while(cin>>randomNumberCount) { int *p = new int[randomNumberCount](); for(int in原创 2017-09-03 11:27:29 · 295 阅读 · 0 评论 -
华为机试-数字颠倒
#include<iostream>#include<string>#include<math.h>using namespace std;void intToString(int nInput){ int nInt; if(nInput!=0) { nInt = nInput % 10; nInput = nInput / 10;原创 2017-09-11 19:28:45 · 250 阅读 · 0 评论 -
华为机试-统计不同字符个数
#include<iostream>#include<string>#include<math.h>using namespace std;int main(){ char szResult[128] = {}; string strInput; while(cin>>strInput) { int nCount=0; int原创 2017-09-08 19:27:49 · 215 阅读 · 0 评论 -
华为机试-取近似值
#include<iostream>using namespace std;int main(){ float fInput; while (cin>>fInput) { int nTemp; nTemp = fInput * 10; int nHight = nTemp / 10; int nLow = n原创 2017-09-07 23:25:08 · 256 阅读 · 0 评论 -
华为机试-质数因子
#include<iostream>#include<string>#include<math.h>using namespace std;int numberCount(int nNumber, int& nCount){ nCount ++; nNumber = nNumber/10; if(nNumber != 0) { nNumber原创 2017-09-07 19:34:55 · 281 阅读 · 0 评论 -
华为机试-字典排序
#include<iostream>#include<string>#include<math.h>#include<vector>#include<map>#include<set>using namespace std;int main(){ int nInput; cin >> nInput; multiset<string> miset; for(原创 2017-09-21 22:33:23 · 732 阅读 · 0 评论 -
华为机试-字符转换
#include<iostream>#include<string>#include<math.h>using namespace std;int main(){ string szInput; int nSum = 0; while(cin>>szInput) { int nLength = szInput.length();原创 2017-09-06 21:14:27 · 273 阅读 · 0 评论 -
剑指-从上到下打印二叉树
1、注意和前序、中序、后序遍历打印区别开来。 2、借助于队列class Solution {public: vectorint> PrintFromTopToBottom(TreeNode* root) { if (!root)return result; que.push(root); while (!que.empty())原创 2018-01-21 17:10:16 · 288 阅读 · 0 评论