01 2015 档案
Summary: Java Inheritance
摘要:In this tutorial we will discuss about the inheritance in Java. The most fundamental element of Java is the class. A class represents an entity and al...
阅读全文
Summary: difference between public, default, protected, and private key words
摘要:According to Java Tutorial:Controlling Access to Members of a ClassAccess level modifiers determine whether other classes can use a particular field o...
阅读全文
Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class
摘要:转自http://www.anylogic.com/anylogic/help/index.jsp?topic=/com.xj.anylogic.help/html/code/Arrays_Collections.htmlJava offers two types of constructs whe...
阅读全文
Leetcode: Largest Number
摘要:聪明方法:其实干嘛要挨个比呢,按最直接的方法,接起来,谁大谁在前: 可以换一下思路,要想比较两个数在最终结果中的先后位置,何不直接比较一下不同组合的结果大小? 举个例子:要比较3和34的先后位置,可以比较334和343的大小,而343比334大,所以34应当在前。 这样,有了比较两个数的方法,就可以
阅读全文
Leetcode: Dungeon Game
摘要:The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a...
阅读全文
Leetcode: Binary Search Tree Iterator
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the ne...
阅读全文
Leetcode: Two Sum III - Data structure design
摘要:The trade off should be considered: In fact, there has to be one operation's time complexity is O(n) and the other is O(1), no matter add or find. So
阅读全文
Leetcode: Two Sum II
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function ...
阅读全文
Leetcode: Fraction to Recurring Decimal
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating,...
阅读全文
Leetcode: Compare Version Numbers
摘要:这道题的意思用一个例子说明就是1.2 < 1.10, 因为1.10跟1.1是不一样的,1.10代表tenth revision. 而1.1代表first revision。所以这道题要按“.”分段,然后分段比较,方法是用split函数把string 分段,每一段挨个比过去。这里参考了网上的一个小技巧
阅读全文
Leetcode: Maximum Gap
摘要:Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 ...
阅读全文
Leetcode: Missing Ranges
摘要:第二遍做法:参考下面一个vimukthi的解答 https://discuss.leetcode.com/topic/18612/accepted-java-solution-with-explanation/3 low 表示next possible missing integer streak的
阅读全文
Leetcode: One Edit Distance
摘要:注意这道题:Must be exactly one distance apart. Not the same. 另外FB面经有一道比较狠的这个题的变形: 这题就是one edit distance的变形题,难点在于给的Iterator,事先不知道两个file的长度,也不允许用extra space(
阅读全文
Leetcode: Longest Substring with At Most Two Distinct Characters
摘要:方法一:用HashMap, map里面存元素及其出现次数。维护一个最大长度。用两个指针,右指针一直走到出现3个dinstinct character为止。然后调整左指针删元素,直接从左往右逐个字符的删除,一直删到某个字符不会再出现。判断字符被删光就看次数是否减为了0. 采用方法: 这里每个元素都会进
阅读全文
Leetcode: Read N Characters Given Read4 II - Call multiple times
摘要:这道题跟I不一样在于,read函数可能多次调用,比如read(buf,23)之后又read(buf, 25), 第一次调用时的buffer还没用完,还剩一个char在buffer里,第二次拿出来接着用,这样才能保证接着上次读的地方继续往下读。 1. 所以应该设置这4个char的buffer为inst
阅读全文
Summary: Stack Overflow Error
摘要:What is a stack overflow error?Parameters and local variables are allocated on the stack (with reference types the object lives on the heap and a vari...
阅读全文
Leetcode: Read N Characters Given Read4
摘要:说明:1. read4(char * buf)的这个buf起初是空的,然后read4读出来的东西存在这个buf里; 2. read函数的buf是destination, 是我们需要往里面依次写通过read4读出来的东西 首先read4是一个读文件的函数,只能读4个char。 char [] buff
阅读全文
Leetcode: Binary Tree Upside Down
摘要:这题第一眼看上去觉得没头绪,不知道怎么上下翻转和左右翻转。但在纸上画几个例子就清楚了。所有的右子树要么为空、要么就是叶子节点且有左子树存在。 那么原来的数一直沿左子树走下去最左的那个节点就是新树的根节点。 这道题最关键在于想到要用递归去做!这种树的结构、父子两层节点关系的问题多半都要用递归去做。这是
阅读全文
Leetcode: Excel Sheet Column Number
摘要:Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A
阅读全文
Leetcode: Factorial Trailing Zeroes
摘要:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Naive方法:A simple method is...
阅读全文
Twitter OA prepare: Rational Sum
摘要:In mathematics, a rational number is any number that can be expressed in the form of a fraction p/q , where p & q are two integers, and the denominato...
阅读全文
Java: Best Way to read a file
摘要:经常在各种平台的online test里面不熟悉STDIN, STOUT,下面举个例子: Input Format There are three lines of input: The first line contains an integer. The second line contains
阅读全文
Summary: gcd最大公约数、lcm最小公倍数算法
摘要:欧几里德算法欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数。其计算原理依赖于下面的定理:定理:gcd(a,b) = gcd(b,a mod b)证明:a可以表示成a = kb + r,则r = a mod b假设d是a,b的一个公约数,则有d|a, d|b,而r = a - kb,因...
阅读全文
Twitter OA prepare: Flipping a bit
摘要:You are given a binary array with N elements: d[0], d[1], ... d[N - 1]. You can perform AT MOST one move on the array: choose any two integers [L, R],...
阅读全文
Twitter OA prepare: Equilibrium index of an array
摘要:Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. For exampl...
阅读全文