- 博客(90)
- 收藏
- 关注
原创 动态代理
参考文献:http://www.jianshu.com/p/6f6bb2f0ece9http://wiki.jikexueyuan.com/project/java-reflection/java-dynamic.html动态代理的好处动态代理中接口中的所有方法都能转移到handler的一个invoke方法中处理;静态代理中每个方法都要有一个对应的代理增强方法;
2017-04-14 16:18:49
369
原创 Java集合
参考文献链接:http://wiki.jikexueyuan.com/project/java-collection/concurrenthashmap.htmlArrayList的实现原理ArrayList底层使用数组实现;空list的默认初始容量大小为10;若添加元素后会超出当前数组的长度,则需要对数组进行扩容,每次扩容约为原数组容量的1.5倍,扩容后一次性把所有元素复制到新的
2017-04-13 21:04:34
360
原创 MySQL索引
一、索引类型普通索引:没有任何限制;唯一索引:索引列必须唯一,但允许为空;逐渐索引:唯一且不许为空;全文索引:用于搜索较长的一篇文章时效果较好;组合索引:一个索引包含多列,遵循“最左前缀”原则;组合索引(A/B/C)与多个单列索引(A、B、C)区别:使用组合索引(A/B/C)相当于分别创建了索引ABC,AB,A;使用三个单列索引,但是查询时Mysql只会用到其中
2017-04-11 15:17:06
471
原创 Spark on Yarn的运行原理
一、YARN是集群的资源管理系统1、ResourceManager:负责整个集群的资源管理和分配。2、ApplicationMaster:YARN中每个Application对应一个AM进程,负责与RM协商获取资源,获取资源后告诉NodeManager为其启动Container。3、NodeManager:每个节点的资源和任务管理器,负责启动/停止Container,并监视资源使用情况
2017-04-09 17:52:44
15011
原创 10、二进制中1的个数
题目输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示我的解法public int NumberOf1(int n) { int[] list = new int[32]; int res = 0; int temp = Math.abs(n); int index = 31; while (temp != 0) { list[index]
2017-03-18 22:07:17
307
原创 两个栈实现队列
题目用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。我的解法import java.util.Stack;public class Solution { Stack stack1 = new Stack(); Stack stack2 = new Stack(); public void push(int
2017-03-17 10:59:18
188
原创 27、二叉搜索树与双向链表
输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。我的解法/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) {
2017-03-15 21:58:10
227
原创 多线程基本知识
一、基本概念一个应用程序就是一个进程,操作系统上可以有多个进程,一个进程中可以有多个线程。一个CPU一个时刻只能运行一个线程,当有多个CPU时可以同时并行运行多个线程,但是线程数大于CPU数时,会有线程处于阻塞状态。二、线程的生命周期状态:新建、就绪、运行、阻塞、死亡。阻塞:线程没有获取CPU资源,不能执行。三、控制线程状态join()方法:在thread1中执
2017-03-07 16:36:31
260
原创 hashmap的原理
HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在。在HashMap中,key-value总是会当做一个整体来处理,系统会根据hash算法来来计算key-value的存储位置,我们总是可以通过key快速地存、取value。下面就来分析HashMap的存取。一、定义 HashMap实现了Map接口,继
2017-03-06 16:37:02
196
原创 Java的socket编程
一、原理服务器端用serversocket对象监控端口。客户端用socket对象发送请求来建立连接,当服务器端收到请求后,用accecpt()方法生成socket对象来建立连接。二、客户端发送、接受示例package grammar;import java.io.*;import java.net.*;public class MyServer { public stati
2017-03-05 16:38:15
229
原创 167. Two Sum II - Input array is sorted
题目Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the tw
2017-03-01 17:15:56
202
原创 7. Reverse Integer
题目Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321我的解答public class Solution { public int reverse(int x) { int max = Integer.MAX_VALUE;
2017-02-28 23:49:37
213
原创 9. Palindrome Number
题目Determine whether an integer is a palindrome. Do this without extra space.我的解法public class Solution { public boolean isPalindrome(int x) { if(x < 0) return false;
2017-02-28 17:35:26
179
原创 13. Roman to Integer(不懂规则)
题目Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.搞不懂换算规则。。。。
2017-02-28 16:26:57
220
原创 66. Plus One
题目Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The
2017-02-28 15:28:03
258
原创 67. Add Binary
题目Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".我的解法public class Solution { public String addBinary(String a, String b)
2017-02-28 11:28:58
178
原创 69. Sqrt(x)
题目Implement int sqrt(int x).Compute and return the square root of x.我的解法public class Solution { public int mySqrt(int x) { int s = 1; int e = x; long mid = 0;
2017-02-28 10:29:03
242
原创 168. Excel Sheet Column Title
题目Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
2017-02-27 21:12:00
207
原创 171. Excel Sheet Column Number
题目Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 .
2017-02-27 20:03:02
204
原创 172. Factorial Trailing Zeroes
题目Given an integer n, return the number of trailing zeroes inn!.我的解法(超时)public class Solution { public int twoNum = 0; public int fiveNum = 0; public int trailingZeroes
2017-02-27 19:40:11
173
原创 231. Power of Two
题目Given an integer, write a function to determine if it is a power of two.我的解法public class Solution { public boolean isPowerOfTwo(int n) { if(n == 0) return false;
2017-02-27 12:00:49
178
原创 258. Add Digits
题目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. Since2 has only
2017-02-27 11:47:50
182
原创 263. Ugly Number
题目Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example, 6, 8 are ugly while14 is not ugly
2017-02-27 11:13:10
161
原创 268. Missing Number
题目Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.我的解法public class So
2017-02-27 10:48:32
151
原创 367. Valid Perfect Square
题目Given a positive integer num, write a function which returns True ifnum is a perfect square else False.Note: Do not use any built-in library function such assqrt.Example 1:Input: 16R
2017-02-26 18:52:59
188
原创 400. Nth Digit
题目Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...Note:n is positive and will fit within the range of a 32-bit signed integer (n 31).Example 1:Inp
2017-02-26 15:11:23
219
原创 415. Add Strings
题目Given two non-negative integers num1 andnum2 represented as string, return the sum ofnum1 and num2.Note:The length of both num1 andnum2 is Both num1 andnum2 contains only digits
2017-02-24 17:54:09
451
原创 453. Minimum Moves to Equal Array Elements
题目Given a non-empty integer array of sizen, find the minimum number of moves required to make all array elements equal, where a move is incrementingn - 1 elements by 1.Example:Input:[1,2
2017-02-24 12:03:43
199
原创 1. Two Sum
题目Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use t
2017-02-23 19:56:46
91
原创 202. Happy Number
题目Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squ
2017-02-23 17:38:39
165
原创 204. Count Primes
题目Description:Count the number of prime numbers less than a non-negative number,n.我的解法(超时)public class Solution { public int countPrimes(int n) { int res = 0; if(n - 1
2017-02-23 16:37:36
143
原创 205. Isomorphic Strings
题目Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced wit
2017-02-23 10:11:25
170
原创 217. Contains Duplicate
题目Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every elem
2017-02-22 22:43:15
153
原创 219. Contains Duplicate II
题目Given an array of integers and an integer k, find out whether there are two distinct indicesi and j in the array such that nums[i] = nums[j] and theabsolute difference between i and j is at
2017-02-22 17:56:20
152
原创 242. Valid Anagram
题目Given two strings s and t, write a function to determine ift is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may
2017-02-22 16:08:17
251
原创 290. Word Pattern
题目Given a pattern and a stringstr, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter inpattern and a non-empty word instr
2017-02-22 14:02:31
193
原创 349. Intersection of Two Arrays
题目Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1],nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The re
2017-02-22 11:17:28
161
原创 350. Intersection of Two Arrays II
题目Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1],nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as m
2017-02-21 22:15:03
142
原创 389. Find the Difference
题目Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling strings and then add one more letter at a random position.Find the letter that
2017-02-21 18:19:49
169
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人