摘要:
The Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.implementation 阅读全文
摘要:
The Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.implementation 阅读全文
摘要:
The Factory Method Pattern defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.implementation 阅读全文
摘要:
The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extendingfunctionality.implementation 阅读全文
摘要:
The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically. Observer Pattern = Publisher + Subcribersimplemenation: 阅读全文
摘要:
1 /** 2 * Definition for singly-linked list with a random pointer. 3 * class RandomListNode { 4 * int label; 5 * RandomListNode next, random; 6 * RandomListNode(int x) { this.label = x; } 7 * }; 8 */ 9 public class Solution {10 public RandomListNode copyRandomList(RandomListN... 阅读全文
摘要:
1 public class Solution { 2 public int[] twoSum(int[] numbers, int target) { 3 HashMap visited = new HashMap(); 4 int[] result = new int[2]; 5 for(int i = 0; i < numbers.length; i++){ 6 int tmp = target - numbers[i]; 7 if(visited.containsKey(tmp))... 阅读全文
摘要:
1 public class Solution { 2 public ListNode addTwoNumbers(ListNode l1, ListNode l2) { 3 if(l1 == null) 4 return l2; 5 if(l2 == null) 6 return l1; 7 ListNode fakehead = new ListNode(0); 8 ListNode pre = fakehead; 9 int carry = 0;10 ... 阅读全文
摘要:
1 public class Solution { 2 public int longestConsecutive(int[] num) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int len = num.length; 6 if(len table = new HashMap(); 9 ... 阅读全文
摘要:
String equals() == 1 public class Solution { 2 public int evalRPN(String[] tokens) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 Stack stack = new Stack(); 6 if(tokens == null |... 阅读全文
摘要:
1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */10 public class Solution {11 public int minDepth(TreeNode root) {12 // IMPORTANT: Please reset any memb... 阅读全文
|