- 博客(10)
- 收藏
- 关注
原创 Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new counts array.The counts array has the property where counts[i] is the number of smaller elements to the right ofnums[i].Example:
2017-05-24 22:04:11 221
原创 红黑树 RBTreee
1. 红黑树是二叉查找树.2. 插入性质:1. 插入新节点总是红色节点2. 如果插入节点的父节点是黑色, 能维持性质3. 如果插入节点的父节点是红色, 破坏了性质. 故插入算法就是通过重新着色或旋转, 来维持性质算法:假设要插入的节点标为N,N的父节点标为P,N的祖父节点标为G,N的叔父节点标为U.1. N = root, N->黑, over。2. P
2017-05-17 13:25:52 238
原创 二叉查找树
1. 查找Status SearchBST(BiTree T, KeyType key, BiTree f, BiTree &p){ if(!T) { //查找不成功 p=f; return false; } else if (key == T->data.key) { //查找成功 p=T; return true; } else if (
2017-05-15 15:59:59 223
原创 HighestBitNum
Java public static int highestOneBit(int i) { // HD, Figure 3-1 i |= (i >> 1); i |= (i >> 2); i |= (i >> 4); i |= (i >> 8); i |= (i >> 16);
2017-05-12 16:55:10 201
原创 树状树组
按照Peter M. Fenwick的说法,正如所有的整数都可以表示成2的幂和,我们也可以把一串序列表示成一系列子序列的和。采用这个想法,我们可将一个前缀和划分成多个子序列的和,而划分的方法与数的2的幂和具有极其相似的方式。一方面,子序列的个数是其二进制表示中1的个数,另一方面,子序列代表的f[i]的个数也是2的幂。三个概念1. Lowest bit number...
2017-05-12 16:08:59 351
原创 LowestBitNum
Given an integer, return an interger which has only one 1 bit, and the postion is as same as the lowest 1 bit of the input.返回输入最低位是1所在位置所代表的数。如 F(0001010) = 10 int x =0x80000000; int r1 = x&(x
2017-05-11 17:01:45 149
原创 Predict the Winner
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a
2017-05-09 13:27:07 186
原创 随机数
Given a singly linked list, return a random node's value from the linked list. Each node must have thesame probability of being chosen. int getRandom() { int res = head->val; Li
2017-05-07 12:54:55 190
原创 算法笔记 - 数组
1. 排序可巧利用数组索引如:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) f
2017-05-02 22:02:26 685
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人