自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

转载 浅拷贝和深拷贝

#include #include class A{public: A() // 构造函数,p指向堆中分配的一空间 { m_data = new char(100); printf("默认构造函数\n"); } A(const A&r) { m_data = new char(100); memcpy(m_data, r.m_data,

2016-07-31 16:50:42 233

原创 回溯法总结

一般回溯法可以用两种框架,一种遍历方式(for循环),选择方式(可以理解成到某一节点选择或者不选)。比较二者的差别:1.采用遍历方式,for(int i=dep;i选择的方式记得判断dep是否到达边界dep==nums.size()同时记得dep++;2.遍历方式中for循环的临时变量存储的是temp[i],选择方式中是temp[dep];3.采用选择方式中,pop完之后还需要继续

2015-10-07 09:02:15 599

原创 栈的压入、弹出序列

输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。class Solution {public: //主要是分析为什么不是一个出栈,先找到对应的序号,比如进栈的序列是1 7 6

2015-09-25 14:01:23 342

原创 调整该数组中数字的顺序

输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。class Solution {public: //类似插入排序,找到什么地方插入,i为最右边的奇数的位置,j为i的左边偶数的位置 void reOrderArray(vector &array) { if (ar

2015-09-24 21:47:23 316

原创 间隔K翻转链表

1->2->3->4->5->6->7 k=3 return 3->2->1->6->5->4->7ListNode * reverse(ListNode *head,int k) { ListNode *pre = NULL; while (k>0) { k--; ListNode *next = head->next; head->next = pre;

2015-09-24 20:45:25 416

原创 旋转数组的最小数字

把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个非递减序列的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。两种特殊情况,未旋转(左值小于右,若旋转过肯定左大于右),或者2 2 2 1 2这种,设两个指针指向两端,然后二分,如果mid大于等于left说明,左端有序,如果mid小于等于右说明右有序。

2015-09-24 10:55:00 275

原创 leetcodes

递归/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class So

2015-09-23 22:30:42 336

翻译 快排

class Solution {public: int Partition(vector &nums, int left, int right) { // 采用子序列的第一个元素为枢纽元素 int pviont = nums[left]; while (left<right) { // 从后往前在后半部分中寻找第一个小于枢纽元素的元素 while(nums[rig

2015-09-15 15:26:28 279

原创 leetcode 链表

Dummy node 是链表问题中一个重要的技巧,中文翻译叫“哑节点”或者“假人头结点”。Dummy node 是一个虚拟节点,也可以认为是标杆节点。Dummy node 就是在链表表头 head 前加一个节点指向 head,即 dummy -> head。Dummy node 的使用多针对单链表没有前向指针的问题,保证链表的head 不会在删除操作中丢失。除此之外,还有一种用法比较少

2015-09-13 15:33:53 358

原创 leetcode Palindrome Linked List 链表

Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?Show TagsShow Similar Problems题目意思是给一个链表,判断是不是回文,比如1->2->3->

2015-07-14 15:58:14 281

原创 leetcode Fraction to Recurring Decimal 哈希表

leetcode Fraction to Recurring Decimal 哈希表

2015-07-14 13:12:26 407

原创 leetcode Repeated DNA Sequences 哈希表

leetcode Repeated DNA Sequences

2015-07-14 11:21:48 335

原创 leetcode Anagrams

leetcode Anagrams

2015-07-14 09:43:51 349

原创 leetcode Two Sum 哈希表

Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where

2015-07-06 19:12:27 303

原创 leetcode Contains Duplicate II 哈希表

Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand j is at most k.

2015-07-06 17:27:09 419

原创 leetcode Flatten Binary Tree to Linked List树

leetcode Flatten Binary Tree to Linked List树

2015-07-06 16:54:27 308

原创 leetcode Count Complete Tree Nodes

leetcode Count Complete Tree Nodes

2015-07-06 15:57:54 419

原创 leetcode Power of Two位运算

Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.Show Tags

2015-07-06 11:27:41 278

原创 leetcode Populating Next Right Pointers in Each Node 树 队列应用

leetcode Populating Next Right Pointers in Each Node 树 队列应用

2015-07-06 11:05:42 321

原创 leetcode Sum Root to Leaf Numbers 树

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota

2015-07-06 09:57:18 293

转载 Longest Substring Without Repeating Characters求最长子串中没有重复字母的最长长度

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo

2015-07-06 09:37:39 341

原创 leetcode Convert Sorted Array to Binary Search Tree 树

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.把一个有序的数组编程平衡二叉搜索树。/** * Definition for a binary tree node. * struct TreeNode { * int val; *

2015-07-05 22:58:54 271

原创 leetcode Symmetric Tree 树

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f

2015-07-05 19:47:07 209

原创 leetcode Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for a binary tre

2015-07-05 17:45:46 239

原创 leetcode Balanced Binary Tree 树

Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe

2015-07-05 17:10:47 237

原创 leetcode Partition List链表

leetcode Partition List链表

2015-07-05 10:49:48 282

原创 leetcode Add Two Numbers 链表

leetcode Add Two Numbers 链表

2015-07-05 10:18:45 304

原创 求无符号数二进制中1的个数&&求一个字符串中最长的连续子串

求无符号数二进制中1的个数&&求一个字符串中最长的连续子串

2015-07-03 18:42:00 1144

原创 旋转数组的二分查找

旋转数组的二分查找

2015-07-03 15:02:16 541

原创 找数组中只出现一次的两个数 位运算

找数组中只出现一次的两个数 位运算

2015-07-03 09:15:35 556

原创 leetcode Swap Nodes in Pairs 链表

leetcode Swap Nodes in Pairs 链表

2015-07-02 16:57:39 267

原创 leetcode Remove Nth Node From End of List 链表 双指针

leetcode Remove Nth Node From End of List 链表 双指针

2015-07-02 10:18:34 323

原创 leetcode Minimum Size Subarray Sum 双指针

leetcode Minimum Size Subarray Sum 双指针

2015-07-02 09:48:23 443

原创 leetcode Binary Tree Zigzag Level Order Traversal 层序遍历 双队列

双队列实现二叉树的层序遍历。

2015-07-01 19:08:02 355

原创 leetcode 二叉树的遍历栈的实现 Preorder Traversal Inorder Traversal Postorder Traversal

leetcode 二叉树的遍历用栈实现 非递归

2015-06-30 21:53:47 384

原创 leetcode Basic Calculator 栈

Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em

2015-06-30 19:31:03 284

原创 leetcode Add and Search Word - Data structure design回溯算法+Trie字典树

leetcode Add and Search Word - Data structure design回溯算法+Trie字典树

2015-06-28 11:03:14 465

原创 leetcode Word Search回溯算法

leetcode Word Search回溯算法

2015-06-27 19:56:53 526

原创 leetcode Generate Parentheses 回溯算法

题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(()

2015-06-26 22:04:35 683

原创 leetcode Combination Sum II回溯问题

最近一直在看回溯算法的框架,这道题代表性比较强,用到剪枝(重复1),和约束(超过界限直接return)。先贴下一般的回溯算法的框架。引用自这个bolg http://blog.jqian.net/post/backtracking.htmlvoid backtrack(int t){ if(t > n) output(x); else for (i

2015-06-26 10:06:46 316

空空如也

空空如也

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

TA关注的人

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