- 博客(18)
- 资源 (2)
- 收藏
- 关注
原创 Path Sum II
题目名称 113. Path Sum II描述 Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.For example: Given the below binary tree and sum = 22, 5
2016-02-29 17:29:55 366
原创 Number of Islands
题目名称 200. Number of Islands描述 Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontall
2016-02-29 15:18:20 485
转载 最全面的C/C++编码规范总结
对于不同的编程语言来说,具体的编码规范可以有很大的不同,但是其宗旨都是一致的,就是保证代码在高质量完成需求的同时具备良好的可读性、可维护性。例如我们可以规定某个项目的C语言程序要遵循这样的规定:变量的命名,头文件的书写和#include 等等。下面是一些广为采用的编码规范:GNU Coding StandardsGuidelines for the Use of the C Language i
2016-02-29 11:41:13 2222
原创 使用vector创建一个二维数组(一)
最近在刷题的时候遇到过好几次二维数组的问题,因为我自己想在C++方向发展,所以尽可能地用C++提供的STL来完成编程,但是在使用二维数组的时候遇到了麻烦,就是如果用int[][]这种直接表示方式很简单,如果用vector的话就有点麻烦,为此我也查了一下资料。 定义一个二维整形数组并初始化:vector<vector<int> > array(m); //这个m一定不能少//初始化一个m*n的
2016-02-29 09:30:09 40719 1
原创 C++ 图的遍历
图的基础知识大家都能搜到,只是最近我在找图算法时看到的C++代码都是很旧之前的版本了,所以这里用了STL来重新写了一遍。图的邻接表存储结构的类型声明//边结点结构类型 struct ANode { int adjvex; //边的终点位置 ANode* nextarc; //指向表头结点下一条邻接的边 int info; //该边的相关信息,对于带权
2016-02-28 18:46:36 7488 1
原创 Populating Next Right Pointers in Each Node II
题目名称 117. Populating Next Right Pointers in Each Node II描述 Follow up for problem “Populating Next Right Pointers in Each Node”.What if the given tree could be any binary tree? Would your previous sol
2016-02-26 15:05:20 419
原创 Binary Tree Zigzag Level Order Traversal
题目名称 103. Binary Tree Zigzag Level Order Traversal描述 Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level
2016-02-26 11:18:58 337
原创 Construct Binary Tree from Inorder and Postorder Traversal
题目名称 106. Construct Binary Tree from Inorder and Postorder Traversal描述 Given inorder and postorder traversal of a tree, construct the binary tree. 分析 这题同样是见我的博客二叉树——根据二叉树遍历序列构造二叉树C++代码/** * Defi
2016-02-25 22:21:32 381
原创 Construct Binary Tree from Preorder and Inorder Traversal
题目名称 105. Construct Binary Tree from Preorder and Inorder Traversal描述 Given preorder and inorder traversal of a tree, construct the binary tree. 分析 详细分析过程见我的博客二叉树——根据二叉树遍历序列构造二叉树C++代码/** * Defin
2016-02-25 22:18:55 482
原创 Lowest Common Ancestor of a Binary Tree
题目名称 Lowest Common Ancestor of a Binary Tree描述 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest c
2016-02-25 17:51:28 321
原创 基础概念
基础概念介绍——导演、场景、层、精灵 在Cocos2d-x-3.x引擎中,采用节点树形结构来管理游戏对象,一个游戏可以划分为不同的场景,一个场景又可以分为不同的层,一个层又可以拥有任意个可见节点(即对象,游戏中基本所有的类都派生于节点类Node)。可以执行Action来修改游戏节点的属性,使其移动、旋转、放大、缩小等。 每一个时刻都有一个场景在独立运行,通过切换不同的场景来完成一个游戏流程,游戏
2016-02-25 11:23:29 403
原创 Binary Tree Postorder Traversal
题目名称 145.Binary Tree Postorder Traversal描述 Given a binary tree, return the postorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1
2016-02-24 22:14:26 357
原创 二叉树——根据二叉树遍历序列构造二叉树
根据前序序列和中序序列构造二叉树 二叉树的节点类型声明如下:struct BTNode { char val; BTNode *left; BTNode *right; BTNode(char c):val(c), left(NULL), right(NULL);};定理1 任何(n>=0)个不同节点的二叉树,都可由它的前序序列和中序序列唯一地确定。 根据前
2016-02-23 20:13:37 1491
原创 new与malloc的区别
一、我们先来看个例子1.new 返回指定类型的指针,并且可以自动计算所需要大小int *p;p = new int; //返回类型为int* 类型(整数型指针),分配大小为 sizeof(int);int* parr;parr = new int [100]; //返回类型为 int* 类型(整数型指针),分配大小为 sizeof(int) * 100;2.malloc 则必须要由我们计算字
2016-02-23 16:34:08 1577
原创 Validate Binary Search Tree
题目名称 Validate Binary Search Tree—LeetCode链接描述 Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nod
2016-02-21 21:01:49 342
原创 反转链表
题目名称 定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。链表节点定义如下:描述 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 tw
2016-02-21 20:54:15 196
原创 二叉树——二叉树的遍历
二叉树遍历(Binary Tree Traversal) 二叉树的遍历是指按照一定次序访问树中所有结点,并且每个结点仅被访问一次的过程。它是最基本的运算,是二叉树中所有其他运算的基础。 重用的4种遍历方法如下: 1.前序遍历 前序遍历的二叉树的过程如下: (1)访问根结点 (2)前序遍历左子树 (3)前序遍历右子树 前序遍历二叉树的递归算法如下://前序遍历(递归
2016-02-21 12:29:52 844
原创 二叉树——基本概念
二叉树(Binary Tree)1.二叉树的定义 二叉树的定义是以递归形式给出的: 一棵二叉树是结点的一个有限集合,该集合或者为空,或者是由一个根节点加上两棵分别称为左子树和右子树的、互不相交的二叉树组成。 二叉树有5种基本形态,如图1所示,任何复杂的二叉树都是这5种基本形态的复合,其中图(a)是空二叉树,图(b)是单结点的二叉树,图(c)是右子树为空的二叉树,图(d)是左子树为空
2016-02-21 11:02:37 901
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人