自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 把排序数组转换为高度最小的二叉搜索树

class Solution {public: TreeNode *sortedArrayToBST(vector &A) { TreeNode *result = buildBST(A,0,A.size()-1); return result; } TreeNode *buildBST(vector &A, int start, int

2016-03-20 16:48:33 262

原创 二叉树的前后中序遍历

前序遍历class Solution {public: vector result; void getNode(TreeNode *root){ result.push_back(root->val); if(root->left != NULL){ getNode(root->left); }

2016-03-20 16:26:27 282

原创 二叉树的最大深度 & 二叉树的最小深度

分治法 二叉树的最大深度class Solution {public: /** * @param root: The root of binary tree. * @return: An integer */ int maxDepth(TreeNode *root) { // write your code here

2016-03-20 15:53:50 479

原创 Paint Fence 栅栏涂色

不能有超过连续两根柱子是一个颜色,也就意味着第三根柱子要么根第一个柱子不是一个颜色,要么跟第二根柱子不是一个颜色。如果不是同一个颜色,计算可能性的时候就要去掉之前的颜色,也就是k-1种可能性。假设dp[1]是第一根柱子及之前涂色的可能性数量,dp[2]是第二根柱子及之前涂色的可能性数量,则dp[3]=(k-1)*dp[1] + (k-1)*dp[2]。class Solution {

2016-03-19 21:44:51 656

原创 A+B

class Solution {public: /* * @param a: The first integer * @param b: The second integer * @return: The sum of a and b */ int aplusb(int a, int b) { // write your c

2016-03-10 17:44:26 245

原创 不同的路径

class Solution {public: /** * @param n, m: positive integer (1 <= n ,m <= 100) * @return an integer */ int uniquePaths(int m, int n) { // wirte your code here v

2016-03-09 12:36:11 265

原创 判断字符串是否没有重复字符

class Solution {public: /** * @param str: a string * @return: a boolean */ bool isUnique(string &str) { // write your code here int ch[128] = {0}; for (

2016-03-09 12:23:33 336

原创 恢复旋转排序数组

难!class Solution {public: int getGCD(int a, int b) { if (a % b == 0) { return b; } return getGCD(b, a % b); } void recoverRotatedSortedArray(

2016-03-08 17:22:59 258

原创 删除排序数组中的重复数字

class Solution {public: /** * @param A: a list of integers * @return : return an integer */ int removeDuplicates(vector &nums) { // write your code here if(nums

2016-03-08 10:09:46 335

原创 合并区间

/** * Definition of Interval: * classs Interval { * int start, end; * Interval(int start, int end) { * this->start = start; * this->end = end; * } */class Solution

2016-03-06 15:35:40 237

原创 最大子数组

class Solution {public: /** * @param nums: A list of integers * @return: A integer indicate the sum of max subarray */ int maxSubArray(vector nums) { // write your

2016-01-24 01:16:16 306

原创 x的平方根——(不知为何这道有点难)

class Solution {public: /** * @param x: An integer * @return: The sqrt of x */ int sqrt(int x) { // write your code here if(x ==1 && x == 0){return x;}

2016-01-23 23:54:23 534

原创 两个链表的交叉——值得注意的错误

class Solution {public: /** * @param headA: the first list * @param headB: the second list * @return: a ListNode */ ListNode *getIntersectionNode(ListNode *headA, ListNode

2016-01-21 14:43:06 202

原创 带环链表

class Solution {public: /** * @param head: The first node of linked list. * @return: True if it has a cycle, or false */ bool hasCycle(ListNode *head) { // write your c

2016-01-21 01:43:42 276

原创 重排链表

给定一个单链表L: L0→L1→…→Ln-1→Ln,重新排列后为:L0→Ln→L1→Ln-1→L2→Ln-2→…必须在不改变节点值的情况下进行原地操作。class Solution {public: /** * @param head: The first node of linked list. * @return: void */

2016-01-20 23:21:27 398

原创 合并k个排序链表

class Solution {public: /** * @param lists: a list of ListNode * @return: The head of one sorted list. */ ListNode *mergeKLists(vector &lists) { // write your code here

2016-01-20 17:47:46 240

原创 翻转链表1和2

class Solution {public: /** * @param head: The first node of linked list. * @return: The new head of reversed linked list. */ ListNode *reverse(ListNode *head) { // wri

2016-01-19 23:45:53 186

原创 链表排序

class Solution {public: ListNode *sortList(ListNode *head) { if(head == NULL || head->next ==NULL){return head;} ListNode *mid = getMid(head); ListNode *right = mid->nex

2016-01-19 21:18:12 216

原创 链表插入排序

class Solution {public: /** ---->[1]----> [3]----> [2]----->[0]---->[NULL](原链表) head 1->next 3->next 2->next 0->next ----->[1]---->[NULL](从原链表中取第1个节点作为只有一个节点的有序链表) dum

2016-01-17 14:13:44 234

原创 删除链表中倒数第n个节点

/** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val = val; * this->next = NULL; * } * }

2016-01-16 18:24:27 214

原创 在O(1)时间复杂度删除链表节点

/** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val = val; * this->next = NULL; * } * }

2016-01-16 17:21:06 279

原创 链表求和

给出两个链表 3->1->5->null 和 5->9->2->null,返回8->0->8->null/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL)

2016-01-14 02:12:18 215

原创 删除排序链表中的重复数字 II

/** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val = val; * this->next = NULL; * } * }

2016-01-14 00:11:13 427

原创 删除链表中的元素

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: /** * @

2016-01-13 19:16:54 199

空空如也

空空如也

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

TA关注的人

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