随笔分类 - java
摘要:O(n^2) solution: Sweep public List<List<Integer>> getSkyline(int[][] buildings) { TreeSet<Integer> edgeSet = new TreeSet<>(); for(int[] building : bui
阅读全文
摘要:Leetcode: https://leetcode.com/problems/implement-trie-prefix-tree/ class Trie { Character curChar; boolean isEnd; Map<Character, Trie> children = new
阅读全文
摘要:分解质因数求最大公约数求最小公倍数牛顿迭代求平方根分解质因数import java.util.ArrayList;import java.util.List;public class Solution { // 返回质因数分解 List getPrimeFactors(int n) { ...
阅读全文
摘要:297. Serialize and Deserialize Binary Tree 思路:preorder遍历 便于deserialize。时空O(N)。 public class Codec { // Encodes a tree to a single string. public Strin
阅读全文
摘要:设计一个类,我们只能生成该类的一个实例。单线程可用,多线程不安全:public class Singleton { private static Singleton instance = null; private Singleton() { } public static ...
阅读全文
摘要:参考:http://blog.csdn.net/fightforyourdream/article/details/16843303import java.util.ArrayList;import java.util.Iterator;import java.util.LinkedList;imp...
阅读全文
摘要:转+修改整理。import java.util.ArrayList;import java.util.Comparator;import java.util.HashMap;import java.util.PriorityQueue;import java.util.Stack;/** * htt...
阅读全文
摘要:检测链表是否是palindrome.思路1:翻转并比较。思路2:迭代。思路3:递归。 public static boolean isPalindrome(LinkedListNode head) { LinkedListNode fast = head; Link...
阅读全文
摘要:You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s ...
阅读全文
摘要:参考http://www.cnblogs.com/jdflyfly/p/3819162.html
阅读全文
摘要:Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.
阅读全文
摘要:Implement an algorithm to find the kth to last element of a singly linked list.
阅读全文
摘要:Write code to remove duplicates from an unsorted linked list.
阅读全文
摘要:Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring ( i.e., “waterbottle” is a rotation of “erbottlewat”).
阅读全文
摘要:Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.
阅读全文
摘要:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?
阅读全文
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.
阅读全文
摘要:类实例化成对象之后,可以通过对象加上"."操作符访问和操纵该对象的域和方法,但是这种访问是有限制的,通过public、protected、default(啥都不写)、private来控制。先看一个实验的例子:(不注释表示可以访问,注释掉表示无法访问)package packageA;import p...
阅读全文
摘要:File类 File 类是jam-io 包下代表与平台无关的文件和目录,也就是说如果希望在程序中操作文件和目录都可以通过File 类来完成,值得指出的是不管是文件、还是目录都是使用File 来操作的, File 能新建、删除和重命名文件和目录, File 不能访问文件内容本身。如果需要访问文件内容本...
阅读全文
摘要:基本顺序为:1 继承体系的所有静态成员初始化(先父类,后子类) 2 父类初始化完成(普通成员的初始化-->构造函数的调用) 3 子类初始化(普通成员-->构造函数) Java初始化顺序如图: 实例代码:package initialization;public class TestInit...
阅读全文

浙公网安备 33010602011771号