自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(102)
  • 资源 (5)
  • 收藏
  • 关注

转载 Sicily 题目分类

依照自己水平挑着做→ →

2014-11-07 23:32:56 1480

原创 LeetCode 153. Find Minimum in Rotated Sorted Array

特殊序列找最小值利用二分public class Solution { public int findMin(int[] nums) { return min(nums, 0, nums.length - 1); } private static int min(int[] a, int begin, int end) {

2015-07-11 16:51:37 436

原创 LeetCode 108. Convert Sorted Array to Binary Search Tree

已排序数组建二叉搜索树根据性质建树即可/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */pu

2015-07-11 16:15:39 444

原创 LeetCode 83. Remove Duplicates from Sorted List

简单链表操作判断重复用hash/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { p

2015-07-11 16:13:50 387

原创 LeetCode 235. Lowest Common Ancestor of a Binary Search Tree

找最小公共祖先递归:只有两个点在根的两侧,他们的公共祖先必为当前根节点。若同侧,则定义最新的根节点。递归直到两节点分开左右,或者其一节点为根节点/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNo

2015-07-11 16:09:20 417

原创 Sicily 1210. 二叉树

知道二叉树的前序遍历和后序遍历求二叉树的棵树可能性关键在于:数拥有单子树的节点个数特征:只有一棵子树的前序假如是AC, 其后序为CA。若有两棵子树,前序为ABC, 后序为BCA。// Problem#: 1210// Author#: Reid Chan#include #include #include using namespace std;int main()

2015-07-11 16:06:00 1338

原创 Sicily 1509. Rails

堆栈的经典应用// Problem#: 1509// Author#: Reid Chan#include #include using namespace std;int main() { int n; int bline[1000]; bool flag; while (cin >> n && n) { flag = false

2015-07-11 16:00:23 927

原创 LeetCode 169. Majority Element

public class Solution { public int majorityElement(int[] nums) { int len = nums.length; int counter = 0, candidate = nums[0]; for (int i : nums) { if (counter =

2015-06-24 21:27:03 357

原创 LeetCode 226. Invert Binary Tree

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {

2015-06-24 21:04:19 313

原创 LeetCode 35. Search Insert Position

public class Solution { public int searchInsert(int[] nums, int target) { int len = nums.length; for (int i = len - 1; i >= 0; i--) { if (nums[i] == target) return i;

2015-06-24 21:02:46 386

原创 LeetCode 217. Contains Duplicate

public class Solution { public boolean containsDuplicate(int[] nums) { Set dupli = new HashSet(); for (int i = 0; i < nums.length; i++) { if (!dupli.contains(nums[i]))

2015-06-24 21:01:03 396

原创 LeetCode 94. Binary Tree Inorder Traversal

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {

2015-06-24 20:59:50 345

原创 LeetCode 116. Populating Next Right Pointers in Each Node

/** * Definition for binary tree with next pointer. * public class TreeLinkNode { * int val; * TreeLinkNode left, right, next; * TreeLinkNode(int x) { val = x; } * } */public class

2015-06-24 20:58:25 391

原创 LeetCode 144. Binary Tree Preorder Traversal

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {

2015-06-24 20:56:05 378

原创 LeetCode 141. Linked List Cycle

/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class

2015-06-24 20:52:41 332

原创 LeetCode 171. Excel Sheet Column Number

public class Solution { public int titleToNumber(String s) { int title = 0, time = 1; int len = s.length(); for (int i = len - 1; i >= 0; i--) { title += ((s.ch

2015-06-24 20:50:18 321

原创 LeetCode 191. Number of 1 Bits

public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int hw = 0, shiftCount = 0; while (shiftCount++ < 32) { hw +=

2015-06-24 20:49:00 396

原创 LeetCode 100. Same Tree

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {

2015-06-24 20:47:37 371

原创 LeetCode 136. Single Number

public class Solution { public int singleNumber(int[] nums) { int ans = 0; for (int i = 0; i < nums.length; i++) { ans ^= nums[i]; } return ans; }}

2015-06-24 20:46:19 385

原创 LeetCode 104. Maximum Depth of Binary Tree

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {

2015-06-24 20:45:03 371

原创 Sicily 1934. 移动小球

用两个数组模拟双向列表// Problem#: 1934// Author#: Reid Chan#include using namespace std;void initial(int *f, int *b, int n) { int i; for (i = 0; i < n; i++) { f[i] = i + 1; } for (i = n; i

2015-06-24 20:41:24 402

原创 Sicily 1443. Printer Queue

按题意思路对于一串序列:子系列1 max1 子序列2 → max1 子序列2 子序列1 (子序列2 子序列1 组成新的子序列3max1 子序列3,子序列3可进一步拆解, 有 max1 (子序列4 max2 子序列5)→ max1 max2 子序列5 子序列 4如此// Problem#: 1443// Author#: Reid Chan#include using n

2015-06-24 20:26:39 397

原创 Sicily 1931. 卡片游戏

直接模拟// Problem#: 1931// Author#: Reid Chan#include using namespace std;void initial(int* arr, int len) { for (int i = 1; i <= len; i++) { arr[i] = i; } for (int j = len + 1; j < 80; j+

2015-06-24 20:23:04 398

原创 Sicily 1194. Message Flood

注意: 不区分大小写, 所以需要转换成统一小写, 方便比较另A为联系人集合, B为发送人集合题意就是求: A - B// Problem#: 1194// Author#: Reid Chan#include #include #include using namespace std;void to_low(string &a, string b, int l) {

2015-05-23 17:12:58 566

原创 Program work 18. Bubble Sort in Java

每轮操作将该轮最大的数放入数组"末尾"最差平均时间复杂度为O(n*n)最好时间复杂度为O(n), 需要加标记, 且数组已排好序的情况下Pseudocode:bubblesort (A : list[0..n-1]) { var i, j; for i from 0 to n-2 { for j from 0 to n-2-i {

2015-04-30 11:13:03 345

原创 Program work 17. Selection Sort in Java

每轮循环将该轮最小的数放在前面已排好的数的末尾最好最坏平均复杂度是O(n*n)Pseudocode:selectionSort (arr){ Find the smallest card. Swap it with the first card. Find the second-smallest card. Swap it with the secon

2015-04-30 11:02:57 472

原创 Program work 16. Radix Sort in Java

不是基于比较的排序是基于位数上的排序, 且仅适用于整数.此位数的排序不会影响前一位数排序好的相对位置, 是stable的排序影响效能的关键在于数组中最大数字的位数最差时间复杂度为O(d*n).另外需要O(n)spaced是最大数字的位数, 决定循环的轮数, n是每轮处理的数目的大小.PseudocoderadixSort (arr, tmp){

2015-04-30 10:32:05 383

原创 Program work 15. Shell Sort in Java

Shell本质上就是insertion sort但是在insertion sort之前, 先做gap大于1的insertion sort这样在最后一步做insertion sort的时候, 由于数组已经接近排序完成所以最后的insertion sort会非常快, 最后一步O(n)时间复杂度根据gap的选取而不同. 这里使用Hibbard的gap, 2的k次方-1: [1,

2015-04-30 10:12:42 351

原创 Program work 14. Insertion Sort in Java

最差时间复杂度: O(n*n)最好时间复杂度: O(n), 已经排好序平均时间复杂度: O(n*n)Pseudocode:for i ← 1 to length(A) - 1 j ← i while j > 0 and A[j-1] > A[j] swap A[j] and A[j-1] j ← j - 1 end w

2015-04-30 10:02:32 290

原创 Program work 13. Heap Sort in Java

关键在于最大堆的建立和重构 (其实两个过程是一样的)因为堆是平衡二叉树, 所以数组可以直接用下标表示父子的节点关系, 数组要从下标1开始.将最大值移到数组只需要O(n)重构堆需要O(lgn)所以upper bound is O(n*logn)事实上, lower bound is  Ω(n*logn) PseudocodeheapSort (arr, len)

2015-04-29 19:51:02 334

原创 Program work 12. Merge Sort in Java

Pseudocode:merge(arr, tmp, begin, end){ if (begin < endl) { get middle mergeSort(arr, tmp, begin, middle); mergeSort(arr, tmp, middle, end); merge(arr, tmp, begi

2015-04-29 16:40:16 408

原创 Program work 11. Quick Sort in Java

原理性的东西请自行google或wiki, 不再累述Pseudocode:quickSort(array, left, right){ index = partion(array, left, right); if (left < index) { quickSort(array, left, index); } if (index < right) {

2015-04-29 16:15:30 578

原创 HBase note. Data Operations and Versions

目前只有四个操作:get: 拿特定rowput: 插入多行新的rows或者更新已有的rowsscan: 获取指定table的指定attributes的rowsdelete: 删除table中的某一行. HBase不会马上delete, 而是会在该行加入tombstones, 而这些rows会在major compaction中才被删除.四个操作的操作对象都是Ta

2015-04-07 14:27:40 403

原创 HBase note. Data model

名词概念.Table: 一个Table由众多rows组成, 需要在建表时就决定Row: 一个row包含row key还有一个或多个columns. Rows以row key按字母从小到大排序, 跟hdfs存储模型一致.Column:  一个column包含一个column family和一个qualifier, 用:隔开Column Family: 一个columns的集合和其

2015-04-01 21:01:22 545

原创 HBase source code. HRegion

配置:hbase.hregion.memstore.flush.size: 134217728当Region的所有的memstore(意思是所有HStore的memstore的size的加总)的size超过参数设定的字节数时, 就会引发flush to disk的这个操作. 其中监听这个value是有另外一条线程在做.hbase.hregion.percolumnfamilyflush

2015-03-26 08:59:57 1204

原创 HBase source code. HStore

配置有部分配置参数已经在StoreFile中介绍过了 StoreFile, 都是跟compaction相关的参数, 重复的不作累赘.hbase.hstore.time.to.purge.deletes: 0是一个延迟清除带有未来时间戳的delete markers的时间的参数. 如果不设置或设为0的话, 所有delete markers连同那些带有未来时间戳的都会在major co

2015-03-19 14:05:36 889

原创 HBase source code. StoreFile

先直接粗暴的介绍在configuration中关于StoreFile的设置, 下文表达的格式为:"属性名: 默认值", 从设置中, 我们大概也可以窥探处, StoreFile可能涉及的操作.hbase.hstore.compaction.min: 3 (以前名为: hbase.hstore.compactionThreshold)如果HStore中的StoreFile的数目超过

2015-03-14 10:04:33 1958

翻译 Technique Java. ReentrantReadWriteLock

网上没有找到比较好的参考文章和实例 → →....这个类有如何几个性质:1. 获得锁顺序. 这个类并不支持按照优先顺序获得锁这种机制, 但是还是能提供一种相对公平获得锁机制. 主要分为两种模式:不公平模式: 这种模式并没有明确指明获取锁的条件, 锁的获取方式是通过线程之间的竞争, 所以这种方式会造成一个或多个读写进程被不断延后, 但是这种方式会比接下来将要介绍的公平模式具有更高

2015-03-12 19:30:13 595

翻译 Technique Java. CountDownLatch

先附上网络上几个比较好的例子:example1, example2, example3CountDownLatch是一个同步的辅助工具, 它允许一个或多个线程等待, 直到一组被其他线程运行的操作完成.CountDownLatch的初始化需要一个给定的数字. 而class中的await()方法会一直被阻塞, 直到初始化时给定的数字减到0, 而使这个数字减到0需要呼叫class

2015-03-09 08:29:12 420

原创 HBase installation. HBase install (1.0.0)

因为需要研究源码的关系个人不会从官网上直接下载安装文件一般选择从git下来maven project, 然后对里面source code进行编译打包生成tar.gz使用这个tar.gz作为安装文件大概流程:git clone git://git.apache.org/hbase.gitcd 到该目录下:mvn eclipse:eclipse (这是为了方便导入e

2015-03-07 09:36:10 593

Docker Up and Running

2015年关于Docker书籍的第二本,有介绍如何安装和运行的docker的详细步骤.一步步带入门

2016-01-02

Pro Apache Hadoop

Hadoop专业应用, 2014出版,已2.x为主, 内含多种实战例子

2015-07-25

Hadoop for dumies

2014出版的, 内容跟得上最新的hadoop版本 从其它committer的视野看hadoop

2015-07-25

空空如也

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

TA关注的人

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