
leetcode
ccbka
本人是重亲大学仪器科学与技术的研究生,专业方向是图像识别,正在关注的领域是深度学习
展开
-
singlenumber
#include using namespace std;class Solution {public: int singleNumber(vector& A) { int result=A[0]; for (int i=0;i { result=result^A[i]; }原创 2017-08-17 22:24:38 · 212 阅读 · 0 评论 -
递归法求最大公约数
#includeusing namespace std;int zdgys(int m, int n){if ((m%n) == 0){return n;}else{int re=zdgys(n, m%n);return re;}}int main(){int m, n;cin >> m >> n;cout return原创 2017-09-26 09:33:04 · 2111 阅读 · 0 评论 -
搜索树的建立,高度的获得,最大值的获得
#includeusing namespace std;typedef struct node{int data;struct node* left;struct node* right;}Node;typedef struct tree{Node* root=NULL;}Tree;void insert(Tree* tree,int value)原创 2017-09-25 17:24:30 · 298 阅读 · 0 评论 -
儿茶搜索树的生长,树的高度,树的最大值,查找某个元素是否在树种,统计元素出现的个数,层序遍历
#includeusing namespace std;typedef struct node{int data;struct node* left;struct node* right;}Node;typedef struct tree{Node* root=NULL;}Tree;void insert(Tree* tree,int value)原创 2017-09-25 21:01:51 · 383 阅读 · 0 评论 -
二叉树定义于前中后序遍历
#includeusing namespace std;typedef struct node{int data;node* left;node* right;}Node;void preorder(Node* root){if (root != NULL){cout data preorder(root->left);preorder(ro原创 2017-09-25 15:18:46 · 246 阅读 · 0 评论 -
结构体的地址与数据成员的地址
#include#includeusing namespace std;int main(){int n;typedef struct node{int data;node* left;node* right;}Node;Node n1;cout coutcout return 0;}原创 2017-09-25 11:02:02 · 2277 阅读 · 0 评论 -
二分查找
#include#includeusing namespace std;class solution{public:int binary_find(vector v,int key,int start,int end){if (start {int mid =(end +start) / 2;if (key == v[mid])return mid;原创 2017-09-22 20:38:09 · 171 阅读 · 0 评论 -
堆排序
#include#includeusing namespace std;class solution {public:void heaping(vector& v, int i,int size)//在假设的基础上构建i节点为根节点的最大堆{if (i{int left = 2 * i + 1;int right = 2 * i + 2;int la原创 2017-09-22 19:26:07 · 158 阅读 · 0 评论 -
小车在货架上取货的路径
要求:在矩形货架上取货,货物重量随机,小车只能向比之前货物更轻的方向行走,求小车能走的最长路径。#include#include#include#include#include#includeusing namespace std;class solution{public:bool pathcore(int* cargo, int i, int j, in原创 2017-08-24 14:56:35 · 408 阅读 · 0 评论 -
递归实现冒泡排序
#include#includeusing namespace std;void bubble_sort(vector& v, int L, int R){if (L == R){return;}for (int i = L; i {if (v[i] > v[i + 1]){int temp;temp = v[i + 1];v[i + 1原创 2017-09-26 09:55:40 · 1940 阅读 · 0 评论 -
判断重复字符串
#include#include#include#include#include#includeusing namespace std;class solution{public:bool check(string s){unordered_map> map_a;for (int i = 0; i {map_a[s[i]].push_ba原创 2017-09-18 16:23:23 · 472 阅读 · 0 评论 -
网易序列操作(泛型reverse算法与vector版)
#include #include #include using namespace std; int main() { vectorint> a; vectorint> b; int n; int tmp; int i; cin >> n; for (i转载 2017-09-03 13:18:22 · 210 阅读 · 0 评论 -
网易等差数列(提交版)
#include#include#include#includeusing namespace std;class solution{public:bool num_ser( int nums[],int length){map cha; sort(nums,nums+length);for (int i = 0; i {int a = nu原创 2017-09-02 21:40:45 · 230 阅读 · 0 评论 -
网易等差数列
如果一个数列S满足对于所有的合法的i,都有S[i + 1] = S[i] + d, 这里的d也可以是负数和零,我们就称数列S为等差数列。小易现在有一个长度为n的数列x,小易想把x变为一个等差数列。小易允许在数列上做交换任意两个位置的数值的操作,并且交换操作允许交换多次。但是有些数列通过交换还是不能变成等差数列,小易需要判别一个数列是否能通过交换操作变成等差数列#include#in原创 2017-09-02 21:26:55 · 197 阅读 · 0 评论 -
网易 彩色砖
小易有一些彩色的砖块。每种颜色由一个大写字母表示。各个颜色砖块看起来都完全一样。现在有一个给定的字符串s,s中每个字符代表小易的某个砖块的颜色。小易想把他所有的砖块排成一行。如果最多存在一对不同颜色的相邻砖块,那么这行砖块就很漂亮的。请你帮助小易计算有多少种方式将他所有砖块排成漂亮的一行。(如果两种方式所对应的砖块颜色序列是相同的,那么认为这两种方式是一样的。)例如: s = "ABAB",那原创 2017-09-02 21:24:24 · 203 阅读 · 0 评论 -
递归版冒泡排序
#include#includeusing namespace std;class solution{public:void bubble_sort(vector& arr,int R){if (R>0){for (int i = 0; i {if (arr[i] > arr[i + 1]){int temp;temp = arr[i];原创 2017-09-19 17:46:40 · 517 阅读 · 0 评论 -
冒泡排序
#include#includeusing namespace std;class solution{public:vector bubble_sort(vector& arr){int arr_len=arr.size();for (int i = 0; i {for (int j = 0; j{if (arr[j]>arr[j + 1])原创 2017-09-19 17:20:50 · 247 阅读 · 0 评论 -
快速排序
#include#includeusing namespace std;class solution{public:void quick_sort(vector& nums,int L,int R){int M = (L + R) / 2;int i = L;int j = R;int temp = nums[M];while (i{whil原创 2017-09-19 10:04:23 · 288 阅读 · 0 评论 -
数字字符串和数字互转
#include#include#include#includeusing namespace std;int main(){int s;//数字转字符串vector v = { 1, 2, 3 };stringstream ss;for (int i = 0; i {ss }string sss;sss = ss.str();/原创 2017-09-18 17:07:28 · 497 阅读 · 0 评论 -
第五次模拟题(DNA)
#include#include#include#include#includeusing namespace std;class solution{public:int cdna(string dnas, unordered_map l){int re = 0;//int temp=-1;vector ree(100,0);for (siz原创 2017-09-05 18:11:49 · 299 阅读 · 0 评论 -
字符矩阵中找字符串路径
#include#includeusing namespace std;class solution{public:bool hascore(const char* Matrix, char* str, const int cols, const int rows, int row, int col, int& pathlength, bool* visited)//{原创 2017-08-23 15:33:08 · 679 阅读 · 0 评论 -
链接两个单向链表
#includeusing namespace std;struct Listnode{int m_data;Listnode* m_next;Listnode(int value, Listnode* next = NULL):m_data(value),m_next(next){}};class solution{public:Listnode* Mer原创 2017-08-19 00:11:26 · 405 阅读 · 0 评论 -
Valid Parentheses(确定输入的括号是否正确)(map edition)
Given a string containing just the characters , determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.#原创 2017-08-18 19:01:45 · 244 阅读 · 0 评论 -
寻找数组中三个数求和为0的组合(naive edition)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: Elements in a triplet (a,b,c) mus原创 2017-08-18 16:58:39 · 1258 阅读 · 0 评论 -
string to integer
String to Integer (atoi)Dec 27 '11Implement 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 a原创 2017-08-18 12:57:37 · 275 阅读 · 0 评论 -
twosum(new edition)
//最优方法 map查找法,map的查询时间复杂度为LogN#include#include#include#includeusing namespace std;class solution{public:vector twosum(vector&num, int& target){map hash;map::const_iterator iter;原创 2017-08-18 10:59:18 · 179 阅读 · 0 评论 -
twosum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sam原创 2017-08-17 23:59:10 · 197 阅读 · 0 评论 -
reverse number
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Note:The input is assumed to be a 32-bit signed integer. Your function should return 0 when the rev原创 2017-08-17 23:04:30 · 403 阅读 · 0 评论 -
由前序遍历和中序遍历重建二叉树
#include#include#includeusing namespace std;struct Binarynode{int m_value;Binarynode* m_left;Binarynode* m_right;Binarynode(int value) :m_value(value), m_left(NULL), m_right(NULL){};原创 2017-08-19 17:36:54 · 206 阅读 · 0 评论 -
由两个栈实现一个队列
#include#include#include//使用栈using namespace std;template class queue{//模板类的定义public:queue(void);~queue(void);void appendtail(const T& num);//成员函数一般是共有的T deletehead();private:sta原创 2017-08-19 21:15:02 · 203 阅读 · 0 评论 -
网易疯狂队列
#include#include#include#includeusing namespace std;class solution{public:int max_v(vector stu){vector newl(2*(stu.size()/2),0);size_t num = stu.size();int times = num / 2;bo原创 2017-09-04 22:44:36 · 328 阅读 · 0 评论 -
网易堆棋子(%60通过率,超内存)
#include#include#include#include#includeusing namespace std;class point{public:point(int x1, int y1):x(x1), y(y1){};private:int x;int y;};class solution{public:vector m原创 2017-09-04 17:48:54 · 252 阅读 · 0 评论 -
网易堆棋子(%60通过率版,超时)
#include#include#include#includeusing namespace std;class solution{public:vector min_step(vector x, vector y, int n){vector dist(n, 0);//为向量赋初值vector re(n,INT_MAX);//使用INT_MAX需要添原创 2017-09-04 17:04:27 · 248 阅读 · 0 评论 -
快速排序(自己实现)
#include#include#includeusing namespace std;class solution{public:void swap(int data[], int randnum, int end){int temp;temp = data[end];data[end] = data[randnum];data[randnum]=原创 2017-09-04 10:51:04 · 252 阅读 · 0 评论 -
优先队列的使用
#include#include#include#includeusing namespace std;templatevoid printpq( const string& str, priorityQ& pr){cout cout cout while (!pr.empty()){cout pr.pop();}cout }原创 2017-08-21 11:43:39 · 188 阅读 · 0 评论 -
堆棋子
网易笔试:堆棋子题目描述小易将n个棋子摆放在一张无限大的棋盘上。第i个棋子放在第x[i]行y[i]列。同一个格子允许放置多个棋子。每一次操作小易可以把一个棋子拿起并将其移动到原格子的上、下、左、右的任意一个格子中。小易想知道要让棋盘上出现有一个格子中至少有i(1 ≤ i ≤ n)个棋子所需要的最少操作次数.输入描述: 输入包括三行,第一行一个整数n(1 ≤ n ≤转载 2017-08-20 14:45:02 · 340 阅读 · 0 评论 -
快速排序的实现与使用
#include#include#include#includeusing namespace std;class solution{public:int randominrange(int a, int b){srand(NULL);//随机数的产生,需要种子int num = a + rand() % (b - a + 1);return num;原创 2017-08-20 13:32:51 · 268 阅读 · 0 评论 -
网易操作排列
小易有一个长度为n的整数序列,a_1,...,a_n。然后考虑在一个空序列b上进行n次以下操作:1、将a_i放入b序列的末尾2、逆置b序列小易需要你计算输出操作n次之后的b序列。 输入描述:输入包括两行,第一行包括一个整数n(2 ≤ n ≤ 2*10^5),即序列的长度。第二行包括n个整数a_i(1 ≤ a_i ≤ 10^9),即序列a中的每个整数,以空格分割。原创 2017-09-03 12:56:45 · 220 阅读 · 0 评论