![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode-c
Lin_drink_caffe
这个作者很懒,什么都没留下…
展开
-
leetcode Reverse Integer
/** * Reverse digits of an integer. * Example1: x = 123, return 321 * Example2: x = -123, return -321 * click to show spoilers. * Note: * The input is assumed to be a 32-bit signed integer. *Your f原创 2017-05-10 23:05:15 · 306 阅读 · 0 评论 -
leetcode: Maximum Depth of Binary Tree
#include <iostream>using namespace std;// Test Unit// Create a tree for test// 1// / \// 2 3// / \ \// 4 5 6// / \// 7 8// /原创 2017-05-09 23:52:29 · 193 阅读 · 0 评论 -
leetcode: sametree
#include <iostream>using namespace std;// Test Unit// Create a tree for test// 1// / \// 2 3// / \ \// 4 5 6// / \// 7 8//原创 2017-05-09 23:53:22 · 258 阅读 · 0 评论 -
leetcode: Search Insert Position
//https://leetcode.com/problems/search-insert-position/#/description#include <iostream>#include <vector>using namespace std;class Solution {public: int searchInsert(vector<int>& nums, int targ原创 2017-05-18 23:22:22 · 281 阅读 · 0 评论 -
直接插入排序 C++
//直接插入排序#include <iostream>using namespace std;void insertSort(int arr[], int length){ int i,j,key; for(i=0;i<length;i++){ key = arr[i]; for(j=i-1;j>=0;j--){ if(ke原创 2017-06-28 18:24:49 · 308 阅读 · 0 评论 -
Leetcode:Roman to Integer
/* * Given a roman numeral, convert it to an integer. * Input is guaranteed to be within the range from 1 to 3999. */#include <iostream>using namespace std;class Solution { public: int roma原创 2017-06-03 15:15:47 · 265 阅读 · 0 评论 -
C++ 希尔排序
ShellSort.h文件#ifndef SHELLSORT_H#define SHELLSORT_H#include <vector>#include <iostream>using std::vector;using std::cout;using std::endl;template <typename T>class ShellSort{private: unsig原创 2017-06-30 11:12:43 · 332 阅读 · 0 评论 -
最小生成树 prim算法
一、prim算法核心问题:用最小的成本连接图中所有的顶点 参考文献: 1、《大话数据结构》 2、http://blog.csdn.net/yeruby/article/details/38615045#//prim算法#include <iostream>#include <fstream>using namespace std;#define MAX 100#define MAXC原创 2017-06-22 21:10:46 · 465 阅读 · 0 评论 -
C++ 冒泡排序
#include <iostream>using namespace std;void my_print(int* pData,int count){ for(int i=0;i<count;i++){ cout<<pData[i]<<" "; } cout<<endl;}void BubbleSort(int* pData,int count){原创 2017-06-27 17:39:23 · 312 阅读 · 0 评论 -
leetcode:Populating Next Right Pointers in Each Node
#include<iostream>#include<vector>#include<stack>using namespace std;// Test Unit//// 1// / \// 2 3// /\ /\// 4 5 6 7// /\ /\ /\ /\// 8 9A BC原创 2017-05-16 22:59:22 · 269 阅读 · 0 评论 -
leetcode 002 Add_Two_Numbers
/*** You are given two non-empty linked lists representing two non-negative integers. * The digits are stored in reverse order and each of their nodes contain a single digit. * Add the two numbers a原创 2017-05-08 23:46:19 · 290 阅读 · 0 评论 -
leetcode:Binary Tree Level Order Traversal 二叉树层序遍历
/** *这是典型的宽度优先算法,利用队列来实现 * **/#include <iostream>#include <vector>#include <queue>using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x)原创 2017-05-16 22:58:33 · 223 阅读 · 0 评论 -
leetcode Best_Time_to Buy and Sell_Stock_II
/** * Say you have an array for which the ith element is the price of a given stock on day i. * Design an algorithm to find the maximum profit. * You may complete as many transactions as you like *(原创 2017-05-10 23:12:30 · 247 阅读 · 0 评论 -
卡特兰数
一,定义卡塔兰数是组合数学中一个常在各种计数问题中出现的数列。以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名。 卡塔兰数的一般项公式为: 其中: 前几项为 (OEIS中的数列A000108): 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 3原创 2017-05-11 14:31:59 · 320 阅读 · 0 评论 -
LeetCode:Unique Binary Search Trees(二叉查找树)
一、BST特点若任意节点的左子树不空,则左子树上所有结点的值均小于或等于它的根结点的值;任意节点的右子树不空,则右子树上所有结点的值均大于它的根结点的值;任意节点的左、右子树也分别为二叉查找树。二、题目Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? For ex原创 2017-05-11 16:07:29 · 306 阅读 · 0 评论 -
Leetcode:Climbing Stairs
#include <iostream>#include <vector>using namespace std;class Solution1{public: int climbStairs(int n){ if(n<=2) { return n; } else {原创 2017-05-22 22:31:47 · 316 阅读 · 0 评论 -
leetcode:Maximum Subarray
#include <iostream>#include <algorithm>#include <vector>using namespace std;class Solution{public: int maxSubArray(vector<int>& nums){ //int n = nums.size(); if(nums.empty()||!n原创 2017-05-23 00:21:55 · 443 阅读 · 0 评论 -
LeetCode: Linked List Cycle
/** *Given a linked list, determine if it has a cycle in it. *Follow up: *Can you solve it without using extra space?*///Unit Test//// |1|-|-->|2|-|-->|3|||// /|\ |// |原创 2017-05-12 12:04:55 · 237 阅读 · 0 评论 -
LeetCode: Binary Tree Inorder Traversal
/** * Given a binary tree, return the inorder traversal of its nodes' values. * For example: * Given binary tree [1,null,2,3], * return [1,3,2]*//// Test Unit/// {1,2,3,#,#,4,#,#,5}/* *原创 2017-05-13 13:53:17 · 266 阅读 · 0 评论 -
leetcode:Binary Tree Preorder Traversal 先序遍历
/** * Given a binary tree, return the preorder traversal of its nodes' values. * Note: Recursive solution is trivial, could you do it iteratively?*//// Test Unit/* * 1 * / \ *原创 2017-05-15 23:58:58 · 276 阅读 · 0 评论 -
简单选择排序 C++
//简单选择排序#include <iostream>using namespace std;void selectSort(int r[], int n){ int i,min,j,temp; //第i遍扫描 for(i=1;i<n;i++){ min=i; for(j=i+1;j<n;j++) { i原创 2017-06-28 13:28:01 · 458 阅读 · 0 评论