JAVA
软货
不想软下去的男人!!!
展开
-
众所周知的二进制
据法国数学教师乔治•伊夫拉①考证:在数字发明之前,古代人类和乌鸦、喜鹊等鸦科动物一样,都无法直接地感知4以上的数目,为了计算羊群、猎物、战士、季节等,人们不得不借助于小石子、贝壳,以及用刀刻槽的办法来计数,比如捕获了1头野兽,就用1块石子指代...世界上除了小时候老师教你的最先进的十进制表达数字的方法,还有很多其他的进制,其中有一些是位值制计数法,十进制就是一种原创 2015-06-17 18:07:14 · 659 阅读 · 0 评论 -
Java实现二叉堆创建
问题描述二叉堆数据结构可以是一个数组对象,他可以视为一个几乎完全的二叉树,最大堆满足对于每一个非根节点,节点的值不大于其父节点的值。程序实现public class MaxHeap { public static int left(int i){ return 2*i; } public static int right(int i){ ret原创 2015-07-05 20:09:51 · 643 阅读 · 0 评论 -
Java堆排序(HeapSort)算法实现
算法实现public class MaxHeap { public static int left(int i){ return 2*i; } public static int right(int i){ return 2*i+1; } public static int heapSize(int [] arr){原创 2015-07-05 20:32:26 · 636 阅读 · 0 评论 -
Java 分治算法实现排序数索引(二分搜索)
递归查找排序整数中数字索引,二分搜索原创 2015-06-08 17:49:32 · 410 阅读 · 0 评论 -
【LeetCode】Basic Calculator II
【LeetCode】Basic Calculator IIImplement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators and empty spaces .原创 2015-07-13 18:06:42 · 685 阅读 · 0 评论 -
【LeetCode】Power of Two
问题描述Given an integer, write a function to determine if it is a power of two. 意:判断一个数是否是2的n次幂算法思想如果一个数小于或等于0,一定不是2的幂次数 如果一个大于0且数是2的n次幂,则其的二进制形式有且仅有一个1,反之成立。算法实现public class Solution { public boole原创 2015-07-06 13:38:38 · 1480 阅读 · 0 评论 -
【LeetCode】Search for a Range
问题描述Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the target is not found i原创 2015-07-06 11:37:27 · 473 阅读 · 0 评论 -
【LeetCode】Kth Smallest Element in a BST
问题描述Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST’s total elements.算法思想BST中序遍历为排序序列,直接技术前k个访问的数原创 2015-07-06 17:15:12 · 594 阅读 · 0 评论 -
【LeetCode】Happy Number
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原创 2015-07-14 12:09:45 · 640 阅读 · 0 评论 -
【LeetCode】Number of Islands
Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or verti原创 2015-07-15 11:21:54 · 642 阅读 · 0 评论 -
【LeetCode】Contains Duplicate II
Contains Duplicate II问题描述Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i原创 2015-07-16 11:03:27 · 1056 阅读 · 0 评论 -
【LeetCode】Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.查找数组主元素原创 2015-07-05 18:21:37 · 585 阅读 · 0 评论 -
Java快速排序(QuickSort)算法实现
Java 快速排序算法实现原创 2015-07-05 17:30:55 · 737 阅读 · 0 评论 -
Ubuntu 14.04 安装 JDK 8
第一步,下载Linux版JDK可以通过访问Oracle官网下载,或者直接通过命令行下载。 I suggest you using follow command to check your system(x86_64=64 bits):ruanhuo@ubuntu:~$ uname -alxh@ubuntu:~$ wget -c http://download.oracle.com/otn-pu转载 2015-06-12 11:08:48 · 413 阅读 · 0 评论 -
计算机整数乘积计算
计算机计算整数乘积的原理: /** * Caculate the multiplication between two integer * @author open201 * */public class Two { /** * Fundamental method * f(n) = O(n^2) * @param a * @param原创 2015-06-08 19:37:07 · 1305 阅读 · 0 评论 -
Java序列划分问题算法实现
Java序列划分问题算法实现问题描述输入: 序列A[p…r] 输出:下标q(p<=q<=r)和原序列A[p…r]的重新排列 新排列满足: A[q] = A[r] A[p…q]中的每一个元素不大于A[q] A[q+1…r]中的每一个元素大于A[q]算法思想算法需要利用A[r]将序列分为两段,总长度依旧为r,可以从左到右扫描序列,逐渐的将不大于A[r]和大于A[r]的数分开。 算法维护两个下原创 2015-06-25 17:19:37 · 709 阅读 · 0 评论 -
使用Java Math.random()利用蒙特卡洛方法计算pi值
/** * Monte Carlo algorithm */import java.math.*;public class PI { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub d原创 2015-06-10 10:56:36 · 785 阅读 · 0 评论 -
Java插入排序算法实现
Java插入排序算法实现问题描述输入:一组数据<a1,a2,a3,...,an><a_1,a_2,a_3,...,a_n> 输出:排序数据<b1,b2,b3,...,bn>,满足b1<b2<b3<...<bn−1<bn<b_1,b_2,b_3,...,b_n>,满足b_1<b_2<b_3<...<b_{n-1}<b_n算法思想插入排序是最简单的排序算法之一,算法思想与我们玩纸牌思想类似,从左手为空原创 2015-06-25 15:01:53 · 505 阅读 · 0 评论 -
Java合并两个有序序列算法实现
Java合并两个有序序列算法实现问题描述输入:序列A<a0,a1,a2,...aq,aq+1,aq+2,...,ar>A<a_0,a_1,a_2,...a_q,a_{q+1},a_{q+2},...,a_{r}>,其中a0<a1<...<aq,aq+1<aq+2<...<ara_0<a_1<...<a_q,a_{q+1}<a_{q+2}<...<a{r} 输出:序列B<b0,b1,...,br>,原创 2015-06-25 16:27:48 · 1846 阅读 · 1 评论 -
【LeetCode】Add Two Numbers
【LeetCode】Add Two Numbers问题描述You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit.原创 2015-06-25 21:13:51 · 430 阅读 · 0 评论 -
Java Hanoi塔问题简单分治算法实现
Java Hanoi塔问题简单分治算法实现问题描述输入:圆盘数n, 3根系杆——起始杆A、过渡杆B、目标杆C 输出:从起始杆到目标杆过程的最少步骤算法思想分治算法思想 如果A上只有一个盘,直接移动到C 如果A上有n个盘,将n-1个盘移动到B,再将A上的一个盘移动到C,随后再利用A将B上的n-1个盘移动到C(与原问题一直)算法实现public class Hanoi { public s原创 2015-06-26 12:47:26 · 3158 阅读 · 0 评论 -
【LeetCode】Longest Substring Without Repeating Characters
【LeetCode】Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters. 查找给定字符串中最长的无重复字符的子串原创 2015-06-26 15:04:09 · 669 阅读 · 0 评论 -
Java 归并排序(MergeSort)算法实现
Java 归并排序(MergeSort)算法实现public class MergeSort { public static void merge(int [] A,int p,int q,int r){ //复制数组 int n = r-p+1; int [] R = A.clone(); int i = p;原创 2015-06-29 10:40:59 · 559 阅读 · 0 评论 -
【LeetCode】Summary Ranges
问题描述Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”]. 意:找出排序数组(无重复数字)中的各个连续的范围原创 2015-06-29 09:46:41 · 1099 阅读 · 0 评论 -
【LeetCode】Contains Duplicate
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 fals原创 2015-07-16 11:21:44 · 609 阅读 · 2 评论