自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

A Little Blog

just do IT

  • 博客(181)
  • 收藏
  • 关注

原创 如何恰到好处地使用protected

package P162_第一小题;class Student { protected String name;//如果不用protected,想想会发生什么? protected int age;// public Student(String name, int age) { this.name = name; this.age = age;

2016-12-08 17:31:55 270

原创 叠罗汉1(最长递增子序列)

问题:如果求一个数列的最长递增子序列?1.下面是一段有bug的代码,输出的结果也是错的,以后作为反面教材,时常复习!package 最长递增子序列;public class 叠罗汉1 { public int getHeight(int[] men, int n) { // write code here if (n == 0) { re

2016-12-08 16:04:37 401

原创 整数变换

package 整数转化;public class Transform { public int calcCost(int A, int B) { // write code here int res = 0; for (int i = 0; i < 32; i++) { if ((A & 1) != (B & 1)) {

2016-12-08 15:14:29 361

原创 负数的二进制表示

负数的二进制表示-20 是 20 的 二进制表示取反加一。20的二进制表示为0010100。0010100取反1101011 加一 得到 1101100。

2016-12-08 15:05:58 998

原创 DiamondProblem(钻石问题)

1.C++的继承设计有问题 2.java的改进 3.遗留的问题package diamondProblem;interface W { static int a = 1;}interface X extends W { static int a = 3;}class Y implements W { static int a = 4;}public class So

2016-12-08 13:37:14 1523

原创 最短路径的算法的学习

1.bellman-ford算法 首先我们约定一些条件: 1. s代表起点 2. d[i]表示从 s 出发到达点 i 的最短距离。那么 考虑一个递推式 d[i] = min{d[j] + (从j到i的边的权值)},j代表和i相邻的点。是否能用这个递推式求最短路径呢?我可以告诉你,其实它是有问题的。想想为什么?

2016-12-06 11:40:53 311

原创 机器人走方格1

package 机器人走方格1;public class Robot { public int countWays(int x, int y) { int[][] dp = new int[12][12]; int maxn = 12; for(int i=1;i<maxn;i++){ dp[1][i] = 1;

2016-12-06 09:38:32 275

原创 概率题(扔硬币)

问题A 有 n 个硬币,B 有 n+1 个硬币,谁丢的正面多谁赢,问 A 不输的概率? 注意:不输二字解法我看了一些网上的答案,大多数写的不是很流畅,所以我尝试写一个清晰易懂的解法,相信小白也可以看懂。 首先考察另一个问题:我们分两个阶段来扔硬币,假设在第一阶段A扔了 n 枚硬币,B扔了 n 枚硬币。并且我们设 P(A>B) 是这个阶段A扔出的硬币出现正面的次数 > B扔出的硬币出现正面的

2016-12-05 13:44:53 3547

原创 平分正方形的直线

package 平分的直线;class Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } public Point() { this.x = 0; this.y = 0; }}public

2016-12-05 11:29:53 350

原创 判断直线相交

package 判断直线相交;public class Solution { static double a = Math.pow(10, -6); public boolean checkCrossLine(double s1, double s2, double y1, double y2) { // write code here return M

2016-12-05 10:55:00 424

原创 找到100亿个url中重复的url以及搜索词汇的topk问题

1.哈希分流到多台机器2.哈希表统计每个机器中的每个小文件3.最小堆(想一想为什么是最小堆?)

2016-12-04 20:59:22 1174

原创 自己动手实现strcpy() memcpy() memmove()等函数

//strcpy()函数char * strcpy(char * strDest, const char * strSrc){ assert((strDest != NULL) && (strSrc != NULL)); char * address = strDest;//为了实现链式表达式,最后返回具体值 while( (*strDest++ = * strSrc++)

2016-12-04 20:00:01 245

原创 海量数据问题

参考:http://www.cnblogs.com/xiaomoxian/p/5161428.html一、只用2GB内存在20亿个整数(32位)中找到出现次数最多的数 解题思路: 想要在很多整数中找到出现次数最多的数,通常的做法是使用哈希表对出现的每一个数做词频统计,哈希表的key是某一个整数,value是这个数出现的次数。就本题来说,一共有20亿个数,哪怕只是一个数出现了20亿次,

2016-12-04 15:34:24 250

原创 二进制插入

//只需要2行代码,nowcoder上的题import java.util.*;public class BinInsert { public int binInsert(int n, int m, int j, int i) { // write code here m<<=j; return n | m; }}

2016-12-04 11:19:22 178

原创 判断链表是否回文

package 回文链表;class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}public class Palindrome { public boolean isPalindrome(ListNode pHead) {

2016-12-04 11:07:04 252

原创 不用加法实现加减乘除

package 求1到n的和;public class Solution { private static int N = 0, sum = 0; public Solution() { N++; sum += N; } public static int getSum(){ return sum; } pu

2016-12-03 15:39:02 189

原创 最近公共祖先

package 最近公共祖先;public class LCA { public int getLCA(int a, int b) { // write code here while (a != b) { if (a > b) { a >>= 1; } else {

2016-12-03 15:06:58 222

原创 输出单层节点

package 输出单层节点;class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}class TreeNode { int val = 0; TreeNode left = null; TreeNode rig

2016-12-03 14:45:03 218

原创 扑克牌顺序

package 扑克牌的顺子;public class Solution { public boolean isContinuous(int[] numbers) { int len = numbers.length; if(len == 0){ return false; } int[] sortArray

2016-12-03 10:33:53 463

原创 清除行列

package 清除行列;public class Clearer { public int[][] clearZero(int[][] mat, int n) { // write code here boolean[] row = new boolean[n]; boolean[] col = new boolean[n];

2016-12-01 21:26:57 175

原创 双栈排序

package 双栈排序;import java.util.*;public class TwoStacks { public ArrayList<Integer> twoStacksSort(int[] numbers) { // write code here Stack<Integer> number = new Stack<Integer>();

2016-12-01 13:50:34 240

原创 attach source(jdk)

我用的是deepin sudo apt-get install openjdk-8-source搞定

2016-12-01 12:49:40 320

原创 访问单个节点的删除

package 访问单个节点的删除;import java.util.*;class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}public class Remove { public boolean removeNode(Lis

2016-12-01 12:01:56 216

原创 链表分割

package 链表分割;import java.util.*;class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}public class Partition { public ListNode partition(ListN

2016-12-01 11:59:54 173

原创 HashMap和HashTable的区别

参考链接:http://stackoverflow.com/questions/40471/differences-between-hashmap-and-hashtable 总结:1. hashmap不是线程安全的 2. hashtable是线程安全的 3. 单线程使用hashmap,因为它更快,或者说时间效率更高

2016-11-30 14:21:32 154

原创 Vector和ArrayList的区别

更加有趣的是: 如果你对此感兴趣,请自己深入探讨。 参考: http://stackoverflow.com/questions/2986296/what-are-the-differences-between-arraylist-and-vector 更新: 我今天打开ArrayList的源码,(如上图所示)如果空间不够,再次分配时增加的空间大小为(oldCapacity >>

2016-11-30 12:27:35 180

原创 StringBuffer和StringBuilder的区别

StringBuffer is synchronized, and StringBuilder is not. It is the main difference between StringBuffer and StringBuilder.Here's a simple benchmark test:public class Main { public static void main

2016-11-30 11:55:10 259

原创 为什么String连接字符串很慢

一段String 连接字符串的用法public String joinWords(String[] words){ String init = ""; for(String s:words){ init+=s;//每次拼接两个字符串 } return init; } 分析:每次拼接两个字符串时,包含

2016-11-30 11:37:01 1106

原创 上楼梯

package 上楼梯;public class GoUpstairs { private static final int MOD = 1000000007; public int countWays(int n) { // write code here if (n == 1) return 1; if (n

2016-11-30 11:24:03 173

原创 原串翻转

C++的解法这里是题目链接 本题要求不能使用额外的空间,所以不能用java做,下面是C++的解法。#include <iostream>using namespace std;class Reverse {public: string reverseString(string iniString) { int len = iniString.length();

2016-11-26 21:35:34 181

原创 确定字符互异

这是题目链接暴力法注意:题目要求不能用额外的空间 时间复杂度 = min( 257 , str.length())* min(257, str.length())import java.util.*;public class Different { public boolean checkDifferent(String iniString) { if(iniStri

2016-11-26 19:29:11 158

原创 构建乘积数组

package 构建乘积数组;import java.util.ArrayList;public class Solution { public int[] multiply(int[] A) { int len = A.length; int[] left = new int[len]; System.arraycopy(A, 0, left

2016-11-26 17:39:25 135

原创 把二叉树打印成多行

package 把二叉树打印成多行;import java.util.ArrayList;import java.util.LinkedList;import java.util.Queue;class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNo

2016-11-26 14:37:26 206

原创 和为S的两个数

package 和为S的两个数;import java.util.ArrayList;public class Solution { public ArrayList<Integer> FindNumbersWithSum(int[] array, int sum) { ArrayList<Integer> res = new ArrayList<Integer>();

2016-11-26 13:11:02 174

原创 把数组排成最小的数

package 把数组排成最小的数;import java.util.Arrays;import java.util.Comparator;public class Solution { public String PrintMinNumber(int[] array) { if (array == null) { return null;

2016-11-26 12:45:19 139

原创 数组中只出现一次的两个数字

package 数组中只出现一次的数;public class Solution { public void FindNumsAppearOnce(int[] array, int num1[], int num2[]) { int len = array.length; int aXorb = 0; for (int i = 0; i < l

2016-11-26 12:24:18 162

原创 数字在有序数组中出现的次数

二分法的应用package 统计一个数在有序数组中出现的次数;public class Solution { public int GetNumberOfK(int[] array, int k) { int len = array.length; if (0 == len) { return 0; }

2016-11-25 21:28:46 276

原创 从1到n的n个整数中1出现的次数

分析暴力解法的优劣 首先这道题是可以用比较暴力的思想解决,是这样的,枚举闭区间 [1, n]中的每一个数,然后计算这每一个数中包含的1的数目,然后将数目累和起来, 就得到了最后的结果。 分析: 1. 时间复杂度:由于 10 进制的整数 N 有 logN 位,所以考察一个整数中含有 1 的个数的代价是 O(log N),一共需要考察 N 个数。所以这种解法的时间复杂度

2016-11-25 16:36:17 180

原创 重建二叉树

package 重建二叉树;class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}public class Solution { public TreeNode reConstructBinaryTree(int[] p

2016-11-25 15:02:05 141

原创 最小的k个数

package 最小的k个数;import java.util.ArrayList;import java.util.PriorityQueue;public class Solution { PriorityQueue<Integer> pq = new PriorityQueue<Integer>(); ArrayList<Integer> res = new ArrayLis

2016-11-24 09:43:04 155

空空如也

空空如也

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

TA关注的人

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