- 博客(145)
- 资源 (5)
- 收藏
- 关注
原创 论volatile
今天和同学讨论java关键字volatile时,他说volatile是同步的,安全的,我说不是,于是我写了如下代码来论证不是同步的,public class Counter { public volatile static int count = 0; public static void inc() { // 这里延迟1毫秒,使得结果明显 try { Thread.slee
2015-09-10 10:31:25
546
转载 .gitignore
原文链接: http://www.javaranger.com/archives/1227 .gitignore有两种文件过滤模式,开放模式和保守模式1.开放模式是设置哪些文件和文件夹要被过滤,例如:帮助1/target/ 表示过滤这个文件夹2.保守模式是设置哪些
2015-05-05 15:43:56
464
原创 LeetCode 76 Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC".
2014-11-26 15:33:58
694
原创 LeetCode 41 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],
2014-11-25 16:28:51
676
原创 LeetCode 43 Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t
2014-11-24 18:46:20
769
原创 LeetCode 87 Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr
2014-11-22 19:43:06
680
原创 LeetCode 39 Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combinati
2014-11-16 22:31:57
408
原创 LeetCode 38 Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number
2014-11-16 22:28:23
499
原创 LeetCode 115 Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none)
2014-11-14 11:00:45
819
原创 LeetCode 71 Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case where path = "/
2014-11-13 16:10:50
827
原创 LeetCode 42 Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.这道题其实是到
2014-11-12 19:13:40
439
原创 LeetCode 48 Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.他的意思就是回文构词法,即单词里的字母的种类和数目没有改变,只是改变了字母的排列顺序。input= ["abc", "
2014-11-12 15:07:23
634
原创 LeetCode 124 Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.
2014-11-12 13:17:52
770
原创 LeetCode 51 N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.思路1:打表public class Solution { public int totalNQ
2014-11-10 18:27:42
644
原创 LeetCode 50 N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.E
2014-11-10 18:22:17
1002
转载 如何用随机函数rand5来构造随机函数rand7
试一下以对话的方式写博~如果看不到人物头像,请刷新页面获取最新的CSS。如果有建议或意见,欢迎到我的微博上跟帖~ 这里是腾讯微博,这里是新浪微博。常规方法今天公司有一个面试题是这样的:假如有一个函数rand5能等概率生成1 - 5 之间的整数,如何利用rand5来实现rand7?rand7函数的要求是能够等概率生成1 - 7之间的整数。说实话我自己也不是很清楚。
2014-11-10 15:20:15
608
原创 LeetCode 72 Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:
2014-11-08 22:39:56
927
原创 Java大数类介绍
java能处理大数的类有两个高精度大整数BigInteger 和高精度浮点数BigDecimal,这两个类位于java.math包内,要使用它们必须在类前面引用该包:import java.math.BigInteger;和import java.math.BigDecimal;或者import java.math.*;下面从几个方面对BigInteger和BigDecima做一个
2014-11-03 16:34:54
1050
原创 atcoder 之February 29th
Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MBProblemCharlie was born January 1st of the year A, on the Earth. He will leave the Earth on December 31st of the year B.He w
2014-11-02 16:14:42
1236
原创 atcoder之A Great Alchemist
C - A Great AlchemistTime limit : 2sec / Stack limit : 256MB / Memory limit : 256MBProblemCarol is a great alchemist.In her world, each metal has a name of 2N (N is an integer) l
2014-11-02 16:03:54
1250
原创 atcoder之A Mountaineer
Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MBProblemDave is a mountaineer. He is now climbing a range of mountains.On this mountains, there are N huts located on a strai
2014-11-02 11:39:02
1377
原创 LeetCode 36 Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku puzzle.
2014-11-01 21:00:04
745
原创 java 集合交并补
通过使用泛型方法和Set来表达数学中的表达式:集合的交并补,在以下三个方法中豆浆第一个参数Set复制了一份,并未直接修改参数中Set。package Set;import java.util.HashSet;import java.util.Set;public class Sets { public static Set intersection(Set s1, Set s2)
2014-10-31 16:55:26
2782
原创 LeetCode 117 Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extr
2014-10-31 10:05:28
924
原创 LeetCode 96 Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3
2014-10-30 20:41:24
564
原创 LeetCode 5 Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.思路1:
2014-10-30 19:56:33
680
原创 LeetCode 131 Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"],
2014-10-27 15:07:00
682
原创 LeetCode 132 Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return 1 s
2014-10-24 17:57:46
777
原创 LeetCode 58 Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2014-10-23 11:01:57
550
原创 LeetCode 53 Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You
2014-10-23 10:56:00
539
原创 LeetCode 146 LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if
2014-10-22 11:52:30
629
原创 LeetCode 148 Sort List
Sort a linked list in O(n log n) time using constant space complexity.思路:要想时间复杂度达到O(n log n) ,那么有两种,一种是合并排序,另一种是快速排序,而要想空间复杂度为常数,那么只能使用递归,本人使用的是递归的合并排序,代码如下:/** * Definition for s
2014-10-22 11:44:26
549
原创 LeetCode 154 Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unkno
2014-10-22 11:32:14
1454
原创 LeetCode 153 Find Minimum in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in the ar
2014-10-22 11:24:12
764
原创 LeetCode 97 Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", retur
2014-10-09 13:17:12
1316
原创 LeetCode 68 Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that is,
2014-09-17 14:07:16
1110
原创 LeetCode 29 Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without an
2014-09-15 13:34:58
759
原创 LeetCode 6 ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I
2014-09-13 21:52:02
725
原创 LeetCode 17 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements
2014-09-09 19:30:14
716
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人