
刷题
LchinaM
这个作者很懒,什么都没留下…
展开
-
生成格雷码
在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同, 则称这种编码为格雷码(Gray Code),请编写一个函数,使用递归的方法生成N位的格雷码。给定一个整数n,请返回n位的格雷码,顺序为从0开始。测试样例:1返回:["0","1"]class GrayCode {public: vector getGray(int n) {原创 2017-03-23 19:29:26 · 493 阅读 · 1 评论 -
刷题
对于数组A[0,1,2,3,4,...,k],求得0#include #include #include "math.h"using namespace std;class Solution{ public: bool maxSum(vector & array, int & result){ if(array.size() <= 1)原创 2017-09-05 15:08:25 · 398 阅读 · 0 评论 -
刷题二
实现带有重复元素的二分查找,如果查找的元素重复,返回重复元素的起始位置。#include #include using namespace std;class Solution{ public: int binarySearch(vector & array, int target){ if(array.size() == 0)原创 2017-09-05 15:37:12 · 272 阅读 · 0 评论 -
刷题三
给出一串数字,判断是否为有效二叉查找树的后序遍历序列(及是否能够通过这串后序遍历序列构造出二叉查找树)#include #include using namespace std;class Solution{ public: bool myCheck(vector & array){ int length = array.size();原创 2017-09-05 16:13:52 · 274 阅读 · 0 评论 -
刷题四
两个有序链表的合并class Solution{ public: Node * myMerge(Node * list1, Node * list2){ if(list1 == null) return list2; if(list2 == null) return list1; Node * head = new Node();原创 2017-09-05 16:45:47 · 250 阅读 · 0 评论 -
刷题五
字符串A和字符串B。是否B包含了A所有的字符#include #include using namespace std;class Solution{ public: bool myCheck(string & str1, string & str2){ if(str1.length() == 0) return true; if(str原创 2017-09-05 16:59:02 · 299 阅读 · 0 评论 -
刷题七
给定一个N位数,例如12345,从里面去掉k个数字,得到一个N-k位的数,例如去掉2,4,得到135,去掉1,5,得到234。设计算法,求出所有得到的N-k位数里面最小的那一个?class Solution{ bool myFunc(vector & array, int m, vector & result){ if(array.size() <= m)原创 2017-09-05 21:17:25 · 364 阅读 · 0 评论