- 博客(13)
- 收藏
- 关注
原创 LeetCode 刷题: 两个二叉树节点的最近公共节点Least Common Ancestor
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw
2015-10-29 23:00:54 394
原创 LeetCode 刷题:int 型数如果转变为二进制数,二进制数里面有几个1
Number of 1 BitsWrite a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has bi
2015-10-29 22:13:02 422
原创 LeetCode 刷题: 左右反转一个二叉树
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-10-28 22:26:08 580
原创 typedef 一个struct
下面的struct:struct node{int data;struct node * next;};要用的时候,必须这样调用:struct node n1;struct node *n2;简单化方法:typedef struct node{int data;struct node *next;} Node, *
2015-10-27 22:43:55 313
原创 LeetCode 刷题:move 一个数组中的所有0 到数组最后
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, 0, 3, 12], after calling you
2015-10-27 22:37:56 906
原创 C++ string 的基本操作(不断更新中)
C++ string 的操作,这篇博客里面讲的比较清楚:c++中string类的详解下面是一些我自己使用过的一些string 的用法:1. 头文件#include // 注意是,不是,带.h的是C语言中的头文件using std::string;using std::wstring;或using namespace std;
2015-10-22 16:45:56 366
原创 如何将int型转换成字符型
比如: 24 ---> '24'.1. 如果要转换的数字是0 -- 9,那么可以这样: int i = 1;char c = 1+'0'2. 如果是个多位数,如 24, 那么最好这样char buffer[50]; //check if 50 is enoughint i = 45;sprintf(buffer, '%d', i);
2015-10-22 16:34:16 3035
转载 散列表的基本概念
网上转来的,拼拼凑凑。我们知道数组能够提供对元素的快速访问但难于扩展;链表易于扩展但不能对其元素进行快速访问。对于大量元素的数据来说,我们当然希望两全其美。散列表提供了达到此目标的一种方法。 散列表(也叫哈希表)是一种查找算法,与链表、树等算法不同的是,散列表算法在查找时不需要进行一系列和关键字(关键字是数据元素中某个数据项的值,用以标识一个数据元素)的比
2015-10-20 10:58:23 447
转载 二叉树的遍历 -- 递归和非递归方法
发现有个博主讲的非常好,代码清晰,转如下:http://blog.csdn.net/sjf0115/article/details/8645991树形结构是一类重要的非线性数据结构,其中以树和二叉树最为常用。二叉树是每个结点最多有两个子树的有序树。通常子树的根被称作“左子树”(left subtree)和“右子树”(right subtree)。二叉树常
2015-10-16 16:54:38 341
原创 LeetCode 刷题4 -- 删除单链表的节点
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value
2015-10-16 13:50:53 284
原创 LeetCode 刷题3 -- 二叉树的最大深度
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.我借鉴的代码(非递归实现)/** * Definition
2015-10-16 11:30:48 402
原创 LeetCode 刷题2 (digit sum)
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on
2015-10-15 14:59:56 347
原创 LeetCode 刷题1
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
2015-10-15 13:57:51 319
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人