Skip to content

Instantly share code, notes, and snippets.

View SeaHub's full-sized avatar

Seahub SeaHub

View GitHub Profile
@SeaHub
SeaHub / 替换空格.cpp
Created April 3, 2017 03:21
剑指 offer - 替换空格
// 题目描述
// 请实现一个函数,将一个字符串中的空格替换成“%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;
@SeaHub
SeaHub / 二维数组中的查找.cpp
Created March 31, 2017 14:42
剑指 offer - 二维数组中的查找
// 题目描述
// 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。
// 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数
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();
@SeaHub
SeaHub / mergeSort.cpp
Created March 15, 2017 09:12
mergeSort(C++)
//
// MergeSort
//
// Created by SeaHub on 2017/3/15.
// Copyright © 2017年 @Seahub. All rights reserved.
//
#include <iostream>
using namespace std;
@SeaHub
SeaHub / InsertionSort.cpp
Created March 14, 2017 02:47
InsertionSort(C++)
//
// InsertionSort
//
// Created by SeaHub on 2017/3/14.
// Copyright © 2017年 @Seahub. All rights reserved.
//
#include <iostream>
using namespace std;
@SeaHub
SeaHub / SelectionSort.cpp
Created March 14, 2017 02:25
SelectionSort(C++)
//
// SelectionSort
//
// Created by SeaHub on 2017/3/14.
// Copyright © 2017年 @Seahub. All rights reserved.
//
#include <iostream>
using namespace std;
@SeaHub
SeaHub / BubbleSort.cpp
Created March 14, 2017 02:16
BubbleSort(C++)
//
// BubbleSort
//
// Created by SeaHub on 2017/3/14.
// Copyright © 2017年 @Seahub. All rights reserved.
//
#include <iostream>
using namespace std;
@SeaHub
SeaHub / JudgeRotatedString(C++).cpp
Last active March 13, 2017 07:32
nowcoder exercise
// 如果对于一个字符串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;
@SeaHub
SeaHub / TraverseTreeOnLevel(C++).cpp
Created March 12, 2017 03:01
nowcoder exercise
// 有一棵二叉树,请设计一个算法,按照层次打印这棵二叉树。
// 给定二叉树的根结点root,请返回打印结果,结果按照每一层一个数组进行储存,
// 所有数组的顺序按照层数从上往下,且每一层的数组内元素按照从左往右排列。保证结点数小于等于500。
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
@SeaHub
SeaHub / HeapSort.cpp
Last active March 11, 2017 12:57
HeapSort(C++)
//
// HeapSort
//
// Created by SeaHub on 2017/3/11.
// Copyright © 2017年 @Seahub. All rights reserved.
//
#include <vector>
#include <iostream>
@SeaHub
SeaHub / BinarySearch.cpp
Last active March 4, 2017 09:36
BinarySearch(C++)
//
// BinarySearch
//
// Created by SeaHub on 2017/3/4.
// Copyright © 2017年 @Seahub. All rights reserved.
//
#include <iostream>
#include <vector>
using namespace std;