- 博客(64)
- 资源 (2)
- 收藏
- 关注

原创 RecyclerView 源码学习(二):一步一步自定义LayoutManager
前言这篇文章实现了一个简单的LayoutManager,重点在于从原理方面一步一步去了解如何自定义一个LayoutManager。麻雀虽小,但五脏俱全。从自定义LayoutManager的layout布局,到scroll滑动,再到添加简单的动画效果。 其实,自定义一个LayoutManager也没那么难。基本概念RecyclerLayoutManafger调用 getViewForPosition
2017-03-13 18:09:37
3393

原创 Android内存泄漏检测与MAT使用
内存泄漏基本概念内存检测这部分,相关的知识有JVM虚拟机垃圾收集机制,类加载机制,内存模型等。编写没有内存泄漏的程序,对提高程序稳定性,提高用户体验具有重要的意义。因此,学习java利用java编写程序的时候,要特别注意内存泄漏相关的问题。虽然JVM提供了自动垃圾回收机制,但是还是有很多情况会导致内存泄漏。 内存泄漏主要原因就是一个生命周期长的对象,持有了一个生命周期短的对象的引用。这样,会导致短
2016-12-21 16:49:50
2680
1

原创 动态规划解题入门
动态规划是一种算法思想,刚入门的时候可能感觉十分难以掌握,总是会有看了题不知道怎么做,但是一看答案就恍然大悟的感觉。结合这一段时间的学习,在这里做一下总结。解题思路在解题的过程中,首先可以主动寻找递推关系,比如对当前数组进行逐步拉伸,看新的元素和已有结果是否存在某种关系。 对于没有思路的题目,求解可以分为暴力递归(回溯),记忆性搜索,递归优化,时间或空间最终优化四个阶段。 在碰到一道可以使用动态
2016-10-28 00:06:19
2022
原创 [LeetCode] Remove Boxes
题目 Given several boxes with different colors represented by different positive numbers. You may experience several rounds to remove boxes until there is no box left. Each time you can choose some
2017-03-28 17:06:43
2360
原创 [leetcode] 树状数组 BIT
Binary Index Tree关于BIT,可以参考一篇文章: http://blog.youkuaiyun.com/int64ago/article/details/7429868。个人的理解是,相当于在原数组建立了一个具备原数组某些区间和的新的数组。这个数组类似于一个数,最上面的节点又下面的节点构成。比如原数组中ak,对BIT中某些节点有影响。构建树的时候从底向上 k += k & -k 更新BIT节点,
2017-03-26 15:43:46
982
原创 [LeetCode] Create Maximum Number
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the same array
2017-03-15 10:13:02
693
原创 [LeetCode] Sliding Window Median
题目 Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value. Examples: [2,3,4] , the
2017-03-08 10:07:54
522
原创 Android RecyclerView源码学习
RecyclerView 的三驾马车LayoutManager掌管RecyclerView的布局,你可以通过它实现一个listview、gridview、瀑布流等效果。LayoutManager主要作用与RecyclerView的measure和layout过程中。LayoutManager是RecyclerView中的一个内部抽象类,具体实现类有GridLayoutManager,LinearLa
2017-02-24 13:40:51
702
原创 [Leetcode] Split Array Largest Sum
Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m suba
2017-02-23 15:25:15
577
原创 KMP的两种写法
KMP算法可以用来匹配模式字符串,或者寻找最小重复单元,比如abcabcabc,最小重复单元就是abc。qweqweqwe,最小重复单元是qwe。寻找最小重复单元就是计算出字符串的最长公共前缀的长度a,如果 a != 0 && len %(len-a) == 0即找到最小重复单元。详细内容见KMP算法 核心在于next数组的计算,因此列出getNext的不同计算方法。1、next[i]表示长度为i
2017-02-12 01:09:39
1160
1
原创 [LeetCode] Max Sum of Rectangle No Larger Than K
题目 Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k. Example: Given matrix = [ [1, 0, 1], [0,
2017-02-09 23:50:43
498
原创 [LeetCode] Reconstruct Itinerary
题目 Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus
2017-02-07 23:37:07
482
原创 [LeetCode] Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], t
2017-02-06 01:01:02
338
原创 [LeetCode] Patching Array
题目 Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array.
2017-02-01 23:53:40
319
原创 Spring配置AOP没有反应
添加AOP很简单,如下添加一个aspect:package com.mk.aop;import org.aspectj.lang.annotation.After;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotati
2017-01-29 23:54:33
4190
1
原创 阿里云maven 镜像
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> 在i
2017-01-26 21:01:08
18159
原创 Spring Boot 1.4.3搭建
做项目时候,为了分出一个获取统一token的模块,采用spring boot进行项目构建。pom.xml文件内容如下:<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
2017-01-26 16:53:33
1556
转载 Spring AOP原理
[原文地址](http://blog.youkuaiyun.com/liushuijinger/article/details/37829049)之前写了一篇关于IOC的博客——《Spring容器IOC解析及简单实现》,今天再来聊聊AOP。大家都知道spring的两大特性是IOC和AOP。IOC负责将对象动态的注入到容器,从而达到一种需要谁就注入谁,什么时候需要就什么时候注入的效果,可谓是招之则来,挥之则去。
2017-01-26 12:36:24
278
原创 Java Spring Redis搭建
Redis安装首先,要去官网安装相应平台的redis,这部分比较简单直接查询即可。配置Spring Redis首先在pom中添加依赖包: <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${r
2017-01-22 17:49:11
677
转载 Servlet 工作原理解析
[原文地址](http://www.ibm.com/developerworks/cn/java/j-lo-servlet/) developerWorks 中国技术主题Java technology文档库 Servlet 工作原理解析
2017-01-22 15:14:34
487
原创 利用WindowManager生成悬浮按钮及悬浮菜单
简介本文模仿实现的是360手机卫士基础效果,同时后续会补充一些WindowManager的原理知识。 整体思路360手机卫士的内存球其实就是一个没有画面的应用程序,整个应用程序的主体是一个Service。我们的程序开始以后,启动一个service,同时关闭activity即可:public class MainActivity extends Activity { private stat
2017-01-21 16:59:10
1857
原创 JVM内存模型、垃圾回收、字节码基础
前言java文件被jvm编译成.class文件,.class文件中全部是二进制的数据。在JVM中用一个8bit的变量类型存储指令,这样0到255可以表示总共256个指令。我们编写的代码被编译成相应的指令码交给计算机执行,而在对代码进行调优的时候,可以读懂编译后的.class文件也是很重要的。基础知识Java内存模型 首先要先了解一下Java的内存模型,我们比较关心的主要有四个部分:堆,虚拟机栈,本
2017-01-19 23:50:10
569
原创 HTTP重定向和请求转发
概念区分请求转发是服务器内部的事情,比如在Java web中,一个HTTP请求到来会开启一个线程并分配一个 Servlet 去进行处理,JSP文件同样是一个Servlet,在服务器内部可能将请求转发到一个JSP并处理。但是这个过程,客户端是看不到的,他所知道的只是一次请求对应返回了一个响应。 在重定向中,客户端给服务端发送了一个HTTP请求,服务端返回一个状态码为301(永久重定向)或302(临时
2017-01-18 11:11:41
1254
原创 [LeetCode] Expression Add Operators
Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value. Exam
2017-01-17 11:28:21
455
原创 安卓手势识别
现在智能手机基本都是触摸操作,点击按钮是一种交互方式,同时手势相关的操作,比如滑动等等同样是很重要的交互方式。这篇文章是对安卓手势交互相关知识点的整理和总结,主要来源基于官方文档。触摸交互中的概念常用事件首先要了解一些常用的事件: ACTION_DOWN:第一个手指按下 ACTION_UP:第一个手指抬起 ACTION_POINTER_DOWN:第二、三、四等等手指按下 ACTION_POI
2017-01-16 16:35:13
486
原创 Spring MVC中利用注解实现XML和Java对象之间的转换
在Spring MVC中,可以通过注解@RequestBody直接将输入的XML字符串转为Java对象,其底层实际上是通过JAXB来实现的。JAXB直接包含在JDK中,通过Demo了解使用:在Bean中,不需要设置getter和setter方法,直接利用XmlRootElement注解设置根节点名称,再利用XmlElement设置子节点名称即可。@XmlRootElement(name = "xml
2017-01-04 23:46:20
6182
1
原创 [LeetCode]Inorder Successor in BST
题目: Given a binary search tree and a node in it, find the in-order successor of that node in the BST.返回一棵BST中给定节点的中序遍历后继节点。就是在中序遍历的顺序中,给定点下一个要遍历的点。方法一:直观逻辑在BST中,进行二分搜索,找到所给节点,然后判断: 1、所给节点p有右子节点,那么后继节
2017-01-04 13:16:25
411
原创 Spring MVC Web 引入静态文件
web.xml配置:<servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextC
2017-01-03 13:59:04
378
转载 Intellij IDEA使用Maven Tomcat Plugin运行web项目
首先,Run ——> Edit Configurations,这时候如下图: 然后点击左上角的加号,可以添加一个新的配置,如下图: 选择Maven,如下图: 下面填上自己的配置信息,点击apply即可以,如下图: 下面可以看到工具栏中会出现自己刚才配置的信息,直接点击run或者debug即可以运行web项目, 私人广告模块。。。下面依然是我建的一个公众帐号,可以关注一下
2016-12-30 13:51:47
945
原创 编译安卓6.0源码并烧录手机
实验环境是Ubuntu14.04。采用手机nexus 5,编译安卓6.0.1源码并烧录安卓。下载源码下载源码时,建议使用科大的镜像源。 先找好适合你手机的源码版本: 然后采用repo的方式,repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b 你的版本。 因为可以采用ipv6,所以速度不错。环境搭建主要步骤按照官方文档
2016-12-30 09:48:26
5265
转载 二分查找之美:二分查找及其变体的正确性以及构造方式
二分查找究竟有多重要?《编程之美》第2.16节的最长递增子序列算法,如果想实现O(n2)到O(nlogn)的时间复杂度下降,必须借助于二分算法的变形。其实很多算法都是这样,如果出现了在有序序列中元素的查找,使用二分查找总能提升原先使用线性查找的算法。然而,虽然很多人觉得二分查找简单,但随手写一写却不能得到正确的结果:死循环、边界条件等等问题伴随着出现。《编程珠玑》第四章提到:提供充足的时间,仅有约
2016-12-28 14:16:21
1058
原创 [LeetCode]Meeting Rooms II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],…] (si < ei), find the minimum number of conference rooms required. For example, Given [[0, 30],[5
2016-12-26 21:55:53
1892
原创 [LeetCode]Word Ladder II
WordLadder I Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that: Only one lette
2016-12-22 21:47:04
408
原创 [LeetCode] Count of Range Sum
题目: Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j),
2016-12-22 01:00:07
577
原创 [Leetcode] 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 of nums[i].Example:G
2016-12-21 00:19:53
758
原创 Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possibl
2016-12-12 16:37:41
321
原创 Basic Calculator相关问题
实现一个计算器,这种题目很大一种可能是使用栈,但是除此之外,也有一种类似于状态机的思想。Basic Calculator 1. Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *
2016-12-11 16:29:09
423
原创 Google VR cardboard寻宝程序编译问题
默认NDK-treasureHunt-sample gradle问题导入官方samples后,本人选择编译的NDK寻宝模块,发现gradle的配置有问题。不管jcenter还是marvenCentral都找不到那几个sdk的依赖。 首先,在treasurehunt下面新建libs文件夹,将libraries的aar拷贝过去。更改根目录的gradle如下: repositories {
2016-12-09 16:44:10
936
原创 回文串问题 Palindrome
回文串问题是一个常见的问题,回文串就是一个字符串头尾指针向中间移动时每一时刻指针指向的字符都相等,比如aabbaa。 判断一个回文串,最简单的方法就是如定义一样,给一个头尾指针,向中间移动判断就行,这里不赘述。 比较巧妙的是利用回文串的性质去解题。最长回文子串问题先看一道题目,地址: https://leetcode.com/problems/longest-palindromic-subst
2016-12-01 22:36:10
619
原创 AndroidStudio编写JNI程序
这会是一个个人调研及尝试的整理。因为公司在用eclipse+cdt编写jni,本人实在用惯了as,所以总结一些as编写jni的方法。AndroidStudio 中C或者C++代码出现各种错误经常as中会出现以下情况: 代码多出标红,没有自动提示,是不是很抓狂。这个问题,也困扰本人好久,今天居然又去查阅了下as官方文档,发现已经支持C++了啊,但是没有找到具体配置。于是自己各种点点点居然试出来了。其
2016-11-22 20:44:43
2304
悬浮窗口及菜单demo
2017-01-21
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人