This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 题目描述 | |
| // 请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 | |
| // 注意:length 为存储空间的大小,而非字符串长度的大小 | |
| class Solution { | |
| public: | |
| void replaceSpace(char *str,int length) { | |
| if (str == NULL || length <= 0) return; | |
| int originalLength = 0; | |
| int numberOfBlank = 0; | |
| int i = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 题目描述 | |
| // 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。 | |
| // 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数 | |
| class Solution { | |
| public: | |
| bool Find(int target, vector<vector<int> > array) { | |
| bool isFound = false; | |
| if (!array.empty()) { | |
| int rowLength = array.size(); | |
| int colLength = array[0].size(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // MergeSort | |
| // | |
| // Created by SeaHub on 2017/3/15. | |
| // Copyright © 2017年 @Seahub. All rights reserved. | |
| // | |
| #include <iostream> | |
| using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // InsertionSort | |
| // | |
| // Created by SeaHub on 2017/3/14. | |
| // Copyright © 2017年 @Seahub. All rights reserved. | |
| // | |
| #include <iostream> | |
| using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // SelectionSort | |
| // | |
| // Created by SeaHub on 2017/3/14. | |
| // Copyright © 2017年 @Seahub. All rights reserved. | |
| // | |
| #include <iostream> | |
| using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // BubbleSort | |
| // | |
| // Created by SeaHub on 2017/3/14. | |
| // Copyright © 2017年 @Seahub. All rights reserved. | |
| // | |
| #include <iostream> | |
| using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 如果对于一个字符串A,将A的前面任意一部分挪到后边去形成的字符串称为A的旋转词。 | |
| // 比如A="12345",A的旋转词有"12345","23451","34512","45123"和"51234"。 | |
| // 对于两个字符串A和B,请判断A和B是否互为旋转词。 | |
| // 给定两个字符串A和B及他们的长度lena,lenb,请返回一个bool值,代表他们是否互为旋转词。 | |
| class Rotation { | |
| public: | |
| bool chkRotation(string A, int lena, string B, int lenb) { | |
| if (lena != lenb) { | |
| return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 有一棵二叉树,请设计一个算法,按照层次打印这棵二叉树。 | |
| // 给定二叉树的根结点root,请返回打印结果,结果按照每一层一个数组进行储存, | |
| // 所有数组的顺序按照层数从上往下,且每一层的数组内元素按照从左往右排列。保证结点数小于等于500。 | |
| struct TreeNode { | |
| int val; | |
| struct TreeNode *left; | |
| struct TreeNode *right; | |
| TreeNode(int x) : | |
| val(x), left(NULL), right(NULL) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // HeapSort | |
| // | |
| // Created by SeaHub on 2017/3/11. | |
| // Copyright © 2017年 @Seahub. All rights reserved. | |
| // | |
| #include <vector> | |
| #include <iostream> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // BinarySearch | |
| // | |
| // Created by SeaHub on 2017/3/4. | |
| // Copyright © 2017年 @Seahub. All rights reserved. | |
| // | |
| #include <iostream> | |
| #include <vector> | |
| using namespace std; |
NewerOlder