- 博客(41)
- 资源 (5)
- 收藏
- 关注
转载 JAVA中关于wait()和sleep()
Java中的多线程是一种抢占式的机制,而不是分时机制。抢占式的机制是有多个线程处于可运行状态,但是只有一个线程在运行。 共同点 : 1. 他们都是在多线程的环境下,都可以在程序的调用处阻塞指定的毫秒数,并返回。 2. wait()和sleep()都可以通过interrupt()方法 打断线程的暂停状态 ,从而使线程立刻抛出InterruptedException。 如果线程A希望立
2015-09-28 16:26:38 825
转载 设计模式之行为型模式
设计模式总结之行为型模式行为型模式设计到算法和对象间的职责分配,不仅描述对象或类的模式,还描述它们之间的通信方式,刻划了运行时难以跟踪的复杂的控制流,它们将你的注意力从控制流转移到对象间的关系上来。行为型类模式采用继承机制在类间分派行为,例如Template Method 和Interpreter;行为对象模式使用对象复合而不是继承。一些行为对象模式描述了一组相互对等的对象如何相互协作
2015-09-28 15:25:35 1236
转载 结构间进程通讯
进程间通信机制1 文件映射 文件映射(Memory-Mapped Files)能使进程把文件内容当作进程地址区间一块内存那样来对待。因此,进程不必使用文件I/O操作,只需简单的指针操作就可读取和修改文件的内容。 Win32 API允许多个进程访问同一文件映射对象,各个进程在它自己的地址空间里接收内存的指针。通过使用这些指针,不同进程就可以读或修改文件的内容,实现
2015-09-28 15:21:22 444
转载 设计模式——结构型模式
设计模式——结构型模式(包含7种) 结构型设计模式是从程序的结构上解决模块之间的耦合问题。包括以下七种模式:1.Adapte适配器模式:Adapter模式通过类的继承或者对象的组合侧重于转换已有的接口,类适配器采用“多继承”的实现方式,带来了不良的高耦合,所以一般不推荐使用。对象适配器采用“对象组合”的方式,更符合松耦合精神。 例如:笔记本 电源适配器,可以将220
2015-09-28 15:19:24 257
原创 leetcode:Interleaving String 使用动态规划求解的java源代码
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", r
2015-09-28 14:24:12 497
原创 leetcode:Longest Valid Parentheses 使用动态规划O(n)思路
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",
2015-09-27 17:08:29 935
原创 leetcode 222:Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely fille
2015-09-26 23:12:55 364
原创 leetcode 179:Largest Rectangle in Histogram 两种算法
Largest Rectangle 使用一般算法和贪心算法进行实现的两种思路分析以及相关代码
2015-09-25 10:35:13 280
原创 leetcode:Kth Largest Element in an Array 使用快速选择算法,以及对其复杂度的分析
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5
2015-09-23 14:56:24 1129
原创 leetcode:Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wi
2015-09-21 00:18:07 315
原创 leetcode:Reverse Linked List
题目分析:把链表反过来,找一个list存链表,逆序遍历建立关系即可。具体代码如下:public ListNode reverseList(ListNode head) { if(head==null) return null; List list=new ArrayList(); ListNode p=head; //存储链表 while(p!=null)
2015-09-20 22:33:31 288
转载 leetcode 238:Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O
2015-09-18 14:18:59 276
原创 leetcode:Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee
2015-09-18 10:42:25 300
原创 leetcode130:Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O XX X
2015-09-17 20:29:46 299
原创 leetcode:151Reverse Words in a String java实现
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".题目分析:太简单了,要注意一点 split可能会返回空串 public String reverseWords(String s) {
2015-09-17 19:15:57 477
转载 leetcode: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
2015-09-17 17:35:58 426
原创 leetcode:Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i an
2015-09-17 10:12:42 389
原创 leetcode:Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve
2015-09-16 16:07:09 342
原创 leetcode:3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c
2015-09-14 22:43:57 234
原创 leetcode: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 "BAN
2015-09-10 15:12:31 447
原创 leetcode:ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first
2015-09-08 14:55:26 253
原创 leetcode:Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexactly once and w
2015-09-07 15:37:39 435
转载 JAVA包装类
Java共有六个包装类,分别是Boolean、Character、Integer、Long、Float和Double,从字面上我们就能够看出他们分别对应于 boolean、char、int、long、float和double。
2015-09-06 21:57:32 355
转载 Struct1和Struct2的区别
http://www.nowcoder.com/test/question/done?tid=1196688&qid=15081#summary
2015-09-06 21:51:51 2855
转载 Java父类子类成员变量初始化
初始化过程是这样的: 1.首先,初始化父类中的静态成员变量和静态代码块,按照在程序中出现的顺序初始化; 2.然后,初始化子类中的静态成员变量和静态代码块,按照在程序中出现的顺序初始化; 3.其次,初始化父类的普通成员变量和代码块,在执行父类的构造方法;4.最后,初始化子类的普通成员变量和代码块,在执行子类的构造方法;
2015-09-06 21:48:37 1777
转载 结构型模式
结构型模式是描述如何将类对象结合在一起,形成一个更大的结构,结构模式描述两种不同的东西:类与类的实例。故可以分为类结构模式和对象结构模式。在GoF设计模式中,结构型模式有:1.适配器模式 Adapter 适配器模式是将一个类的接口转换成客户希望的另外一个接口。适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。 两个成熟的类需要通信,但是接口不同
2015-09-06 20:58:37 335
转载 Java中List删除
Iterator it = list.iterator();intindex = 0;while(it.hasNext()){ Object obj = it.next(); if(needDelete(obj)) //needDelete返回boolean,决定是否要删除 {
2015-09-06 20:54:16 590
转载 HashMap&HashTable
以下内容均转自百度百科: HashMap: 基于哈希表的 Map 接口的实现。此实现提供所有可选的映射操作,并允许使用 null 值和 null 键。(除了非同步和允许使用 null 之外,HashMap 类与 Hashtable 大致相同。)此类不保证映射的顺序,特别是它不保证该顺序恒久不变。 此实现假定哈希函数将元素适当地分布在各桶之间,可为基本操作(get 和 put)提
2015-09-06 20:45:58 367
原创 关于JAVA中if表达式中的赋值语句
例一:public static void main(){boolean x=false;if(x=true){System.out.print(x);}}注意:这是编译可以通过的,会打印出true;例二:public static void main(){int x=0;if(x=1){System.out.print(x);}
2015-09-06 20:36:33 8871
原创 leetcode:Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t
2015-09-06 20:21:15 423
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人