自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(33)
  • 收藏
  • 关注

原创 清单

***************************Day1******************************* 反转链表: 1.[LeetCode]206.Reverse Linked List — 最原始的单纯的反转链表 http://blog.csdn.net/iamxiaofeifei/article/details/770750212.[LeetCode]92.Reve

2017-09-02 09:48:53 404

原创 递归和回溯法

17. Letter Combinations of a Phone Numbervector<string> letterCombinations(string digits) { vector<string> result; if(digits.empty()) return vector<string>(); static const vector<string> v

2017-08-03 14:12:19 444

原创 二叉树笔记

二叉树的天然递归结构二叉树递归查找元素 二叉树递归释放空间 复习二叉树相关的所有操作 104. Maximum Depth of Binary Treestruct TreeNode { int val; TreeNode* left; TreeNode* right; TreeNode(int x): val(x), le

2017-08-02 14:12:16 483 1

原创 栈、队列、优先队列笔记

20. Valid Parentheses 150. Evaluate Reverse Polish Notation 71. Simplify Path 144. Binary Tree Preorder Traversal 94. Binary Tree Inorder Traversal 145. Binary Tree Postorder Traversal 341. Flatt

2017-08-01 13:41:04 410

原创 C++刷题常用

INT_MAX, INT_MIN atoi atoi(s.substr(0,2).to_str()) heap、make_heap、pop_heap、push_heap sort sort(a.begin(), a.end(), greater) sort(a.begin(), a.end(), compare)

2017-07-31 14:43:59 756

原创 链表笔记

链表相关的笔记 206. Reverse Linked List/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class S

2017-07-31 12:56:53 313

原创 动态规划笔记

283. Move Zeroes 27. Remove Element 26. Remove Duplicates from Sorted Array 80. Remove Duplicates from Sorted Array II 283. Move Zeroes// 解法一:最直观的解法,新建一个vector res,遍历nums,将非0元素依次赋值入res即可//

2017-07-25 11:03:50 326

原创 【剑指offer】最小的K个数

题目描述 输入N个整数,找出其中最小的K个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,。 解:使用堆这一数据结构,时间复杂度为O(NlgK)class Solution {public: vector<int> GetLeastNumbers_Solution(vector<int> input, int k) {

2017-07-24 22:37:38 261

原创 百度2017春招笔试真题编程题集合

寻找三角形#include <iostream>#include <vector>#include <math.h>#include <stdio.h>#include<algorithm>#include <string>using namespace std;bool isSameColor(vector<int>&a, vector<int>&b, vector<int>&c){

2017-06-20 16:46:41 366

原创 面试题61:按之字形顺序打印二叉树

题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推。 解: 两个栈/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x)

2017-04-28 22:52:33 273

原创 面试题60:把二叉树打印成多行

题目描述 从上到下按层打印二叉树,同一层结点从左至右输出。每一层输出一行。 解: 队列实现/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right

2017-04-28 22:51:30 279

原创 面试题59:对称的二叉树

题目描述 请实现一个函数,用来判断一颗二叉树是不是对称的。注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的。 解: 递归/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(

2017-04-28 22:50:09 277

原创 面试题58:二叉树中的下一个结点

题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。 解:/*struct TreeLinkNode { int val; struct TreeLinkNode *left; struct TreeLinkNode *right; struct TreeLinkN

2017-04-28 22:48:53 349

原创 面试题39_2:平衡二叉树

题目描述 输入一棵二叉树,判断该二叉树是否是平衡二叉树。 解:class Solution {public: bool IsBalanced_Solution(TreeNode* pRoot) { if(pRoot == NULL) return true; if(abs(heightOfTree(pRoot->left)

2017-04-28 22:45:31 287

原创 面试题39:二叉树的深度

题目描述 输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 解: 递归/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) :

2017-04-28 22:40:58 196

原创 面试题25:二叉树中和为某一值的路径

题目描述 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。 解: 带记忆的DFS/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x

2017-04-28 22:38:07 286

原创 面试题24:二叉搜索树的后序遍历序列

题目描述 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。 解: 二叉搜索树有序+ 后序遍历特点class Solution {public: bool VerifySquenceOfBST(vector<int> sequence) { // 假定空序列结果为fals

2017-04-28 22:35:02 267

原创 面试题23:从上往下打印二叉树

题目描述 从上往下打印出二叉树的每个节点,同层节点从左至右打印。 解: 层次遍历/*struct TreeNode {int val;struct TreeNode *left;struct TreeNode *right;TreeNode(int x) :val(x), left(NULL), right(NULL) {}};*/class Solution {

2017-04-28 22:27:45 284

原创 面试题19:二叉树的镜像

题目描述 操作给定的二叉树,将其变换为源二叉树的镜像。 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8

2017-04-28 22:25:41 310

原创 面试题18:树的子结构

题目描述 输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构) 解: 见注释/*struct TreeNode {int val;struct TreeNode *left;struct TreeNode *right;TreeNode(int x) :val(x), left(NULL), right(NULL) {}};*/

2017-04-28 22:23:36 214

原创 面试题6:重建二叉树

题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。 解: 递归/*** Definition for binary tree* struct TreeNode {* int val;

2017-04-28 22:20:51 502

原创 面试题27:二叉搜索树与双向链表

题目描述 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。 解: 见代码注释/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) :

2017-04-28 21:46:45 212

原创 面试题63:二叉搜索树的第k个结点

题目描述: 给定一颗二叉搜索树,请找出其中的第k大的结点。例如, 5 / \ 3 7 /\ /\ 2 4 6 8 中,按结点数值大小顺序第三个结点的值为4。解: 二叉搜索树的一个重要性质就是它的中序遍历是排序的,因此这道题目只需要用中序遍历一棵二叉搜索树,找到第K个遍历的结点输出即可。可用递归或者迭代解决此题。/*struct TreeNode { int val; stru

2017-04-27 00:15:45 282

原创 【LeetCode-Python】136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me

2016-10-19 22:55:35 715

原创 【LeetCode-Python】292. Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the

2016-10-19 11:31:03 600

原创 【LeetCode-Python】412. Fizz Buzz

Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For n

2016-10-19 09:36:25 2749

原创 【LeetCode-Python】344. Reverse String

Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.Solution[Python]:class Solution(object): def reverseString(self, s):

2016-10-09 09:26:52 637

原创 [LeetCode-91] Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine the total number of

2016-04-10 20:46:05 465

原创 [LeetCode-9] Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.Solution[C++]:class Solution {public: bool isPalindrome(int x) { if(x < 0) return false; int t

2016-04-10 13:52:47 382

原创 [LeetCode-70] Climbing Stairs

[LeetCode-70] Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Solutio

2016-04-05 18:05:03 350

原创 [LeetCode-230]Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the BST is modif

2015-12-27 14:10:03 347

原创 [LeetCode-283] Move Zeroes

[LeetCode-283]Move Zeroes写在前面:待补充。。。Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1,

2015-12-24 00:32:57 491

原创 LIBSVM的安装——Mac/Windows

LIBSVM的安装——Mac/WindowsMac下LIBSVM的安装环境:OS X10.10+Xcode6.4+MATLAB2014b+libsvm3.20Windows下安装环境:Windows xp+vs2010+MATLAB2013a+libsvm3.20

2015-11-20 12:59:42 1662 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除