自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Grok coding

For sustained progress 关注大数据技术

  • 博客(28)
  • 资源 (3)
  • 收藏
  • 关注

原创 [LeetCode]Container With Most Water

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

2015-04-21 21:20:19 612

原创 [LeetCode]Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]

2015-04-20 09:14:31 689

原创 [LeetCode] Search in Rotated Sorted Array

题意:在旋转的有序数组中搜索某个元素,无重复数据思路:二分搜索,注意有旋转的区间的上下界的判断代码: public int search(int[] A, int target) { return bsearch(A, target, 0, A.length - 1); } /** * 二分搜索,无重复元素,判断是否为rotated

2015-04-18 09:09:26 824

原创 [LeetCode]Remove Duplicates from Sorted Array2

题意:从有序数组中删除重复数据,但是与题目一有一点区别:可以允许重复一次思路:首先判断是否重复,有的话指针后移,然后按照题1中的思路进行,复杂度O(N)代码: public int removeDuplicates(int[] A) { if(A == null || A.length == 0)return 0; int len = A.leng

2015-04-18 09:05:47 810

原创 [LeetCode]Next Permutation

题意: 找出当前数组排列的下一个排列,按升序,如果没有下一个排列就输出最小的排列思路:倒序寻找升序序列直到某个元素不满足逆升序为止,然后交换该元素与其后面比他大的最小元素,最后将后续元素按升序排序即可代码: public void nextPermutation(int[] num) { int j = num.length - 1; int i

2015-04-18 09:02:35 831

原创 [LeetCode]Longest Consecutive Sequence

题意:在一堆无序元素中找到最长的连续串的长度,要求时间复杂度O(N)思路:首先将元素放到set集合中,然后再判断,每次判断是否包含某元素的复杂度为O(1)代码: public int longestConsecutive(int[] num) { int currLen = 0, longestLen = Integer.MIN_VALUE; Se

2015-04-18 08:58:07 921

原创 [LeetCode] Find Minimumin Rotated Sorted Array II

题意:在旋转过的有序数组中找到最小数,数组中可能有重复元素思路:二分,判断是否有相等的元素,主要是二分的时候的一些细节,比如说是有序的还是rotated代码: public int findMin(List nums) {//solution1 O(log(N)) int min = Integer.MAX_VALUE; int l = 0, r

2015-04-18 08:54:44 941

原创 HBase createTable 的服务器端实现源码分析

HBase的所有请求调用都是通过RPC的机制进行的,RPCServer监听到请求之后会解析请求内容,然后根据解析的方法以及参数调用服务器端实际的方法,这也是远程代理模式的经典做法,createTable的请求最终实现是在HMaster中的,但是实际的表的建立过程是在CreateTableHandler类中的,接下来主要就HBase中表的建立过程进行详细分析。1. HMaster的createTab

2015-04-17 14:00:38 2000

原创 [LeetCode]Pascal's Triangle 1 & 2

这两题都比较简单,第一题输出杨辉三角,第二题输出特定的某一行,第二题要求空间复杂度为O(k)代码如下:Pascal's Triangle: public List> generate(int numRows) {//direct simulate List> rs = new LinkedList>(); if(numRows == 0)retur

2015-04-15 13:57:51 670

原创 HBase1.0.0源码分析之请求处理流程分析以Put操作为例(二)

HBase1.0.0源码分析之请求处理流程分析以Put操作为例(二)1.通过mutate(put)操作,将单个put操作添加到缓冲操作中,这些缓冲操作其实就是Put的父类的一个List的集合。如下: private List<Row> writeAsyncBuffer = new LinkedList<>(); writeAsyncBuffer.add(m);当writeAsyncBu

2015-04-13 22:17:06 1497

原创 HBase1.0.0源码分析之请求处理流程分析以Put操作为例(一)

如下面的代码所示,是HBase Put操作的简单代码实例,关于代码中的Connection connection = ConnectionFactory.createConnection(conf),

2015-04-13 17:10:32 1631 1

原创 [LeetCode]Combination Sum

题意:求一个数组中的组合为某个target的所有子数组组合,要求不重复,思路:先将数组排序,然后按深度遍历的思想对i - > len -1的元素进行遍历代码如下:public class Solution { public List> combinationSum(int[] candidates, int target) { List> results = n

2015-04-07 21:47:47 717

原创 [LeetCode]Unique Paths II

该题和之前的题目之间的区别就是某些单元是不可达的,这可以加上判断语句即可算法1:public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int pathsNum = 0,m = obstacleGrid.length,n=obstacleGrid[0].l

2015-04-06 16:43:36 398

原创 [LeetCode]Plus One

简单题不解释, 维护一个进位即可public class Solution { public int[] plusOne(int[] digits) { int c = 1; for(int i = digits.length - 1; i >=0; i --){ if(c == 0)break; digits[i]

2015-04-06 16:00:06 813

原创 [LeetCode]Set Matrix Zeroes

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.in place,主要是感觉比较麻烦,其实就是利用第一行和第一列保存该行列是否需要变0,再用两个变量表示第一行和第一列是否需要变0代码:public class Solution { publi

2015-04-06 15:39:19 770

原创 [LeetCode]Rotate Image

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路1:直接开辟一个数组,然后按照对应关系复制即可,空间和时间复杂度o(N*N)代码1:

2015-04-06 13:58:22 632

原创 [LeetCode]Minimum Path Sum

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right

2015-04-06 12:44:11 954

原创 [LeetCode]Sort Colors

Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integer

2015-04-06 10:56:52 900

原创 [LeetCode]First Missing Positive

题意:在乱序数组中找到第一个没出现的正整数思路1: 直接暴力解决,复杂度O(N*N)代码1: public int firstMissingPositive1(int[] A) {// big O(N*N) if(A.length == 0)return 1; int i = 1; while(i <= A.length){

2015-04-05 21:28:48 514

原创 [LeetCode]Find Peak Element

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks,

2015-04-05 17:09:52 692

原创 [LeetCode]Unique Paths

题意: https://leetcode.com/problems/unique-paths/A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at a

2015-04-05 16:27:48 546

原创 [LeetCode]Find Minimum in Rotated Sorted Array

题意:从一个平移过的数组中找到最小的元素思路1:最简单的思路莫过于排序然后取第一个元素,复杂度O(N*log(N))代码1:public class Solution { public int findMin(int[] num) { Arrays.sort(num); return num[0]; }}思路2: 遍历,比较两段

2015-04-05 15:51:14 565

原创 [LeetCode]Majority Element

题意: 找出一个数组中的主要元素,主要元素为出现次数大于[n/2]的元, 当然最笨的方法就是暴力,没式不知道时间行不行思路1: 遍历数组,统计每个元素出现的次数,用HashMap统计每个元素出现的次数 时间复杂度O(N),空间复杂度 O(N)代码1:public class Solution { public int majorityElement(int[] num)

2015-04-05 15:15:38 672

原创 [LeetCode] Search Insert Position

题意: 给出一个target找出他在有序数组中的位置思路1: 直接遍历 复杂度O(N)代码1: public int searchInsert1(int[] A, int target) {//直接遍历 算法O(N) int i = 0; if(target < A[0]) return 0; if(target > A[A.len

2015-04-04 10:56:57 693

原创 [LeetCode]Merge Sorted Array

题意;将A,B连个有序数组合并到A中,A空间充足思路1: 基本思路很简单,开辟一个额外数组,空间复杂度和时间复杂度都为O(N)代码1:public class Solution { public void merge(int A[], int m, int B[], int n) { if(n == 0)return; if(m == 0){

2015-04-03 20:54:05 507

原创 [LeetCode]Rotate Array

题意:给定一个数组,求该数组向右平移k个位置之后的数组,例如:[1,2,3,4,5,6,7] k = 3 => [5,6,7,1,2,3,4,5,6]思路1:最简单的想法必然是暴力啊,一个个的平移,复杂度O(K*N),代码简洁,也能够通过代码1: public void rotate3(int [] nums, int k){//一次移动一个 if(k ==0 )

2015-04-03 18:38:23 564

原创 [LeetCode]3Sum

题意: 找出一个数组内和为0的三元组,元组不能重复思路1:.直接暴力DFS,这样会超时,不过先排序加上剪枝的花据说能够AC思路2:先排序O(N*log(N)),然后遍历a 从0 到 nums.length - 2, 结下来的问题就简化为2Sum的问题了 复杂度O(N*N)代码: public List> threeSum(int[] num) { List>

2015-04-01 18:06:01 722

原创 HBase1.0.0源码分析之Client启动连接流程

我们知道在使用HBase的过程中首要的是和服务器端取得链接,那么客户端是如何去链接的,它是怎么找到master和regionserver的? 参与该过程中的主要组件又有哪些?这些组件之间是如何协同工作的呢? 今天就让我们来一起解析.

2015-04-01 10:39:36 1705

hbase权威指南中文

目前讲habse最全面的书籍,虽然有点老但是也没新的,可以参考

2014-08-01

新浪微博用户页面解析UserHomePagePrase

该源码展示了解析新浪微博页面的一般方法和技巧

2014-06-15

微博爬虫源代码-WeiboRobot

新浪微博爬虫登录以及页面下载组件,use it anywhere you want

2014-06-09

空空如也

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

TA关注的人

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