随笔分类 - Summary
Leetcode: Pow(x, n) and Summary: 负数补码总结
摘要:Analysis: Time Complexity: O(LogN) Iterative code: refer to https://discuss.leetcode.com/topic/40546/iterative-log-n-solution-with-clear-explanation N
阅读全文
Summary: Difference between null and empty String
摘要:String s1 = "";means that the emptyStringis assigned tos1. In this case,s1.length()is the same as"".length(), witch will yield0as expected.String s2 =...
阅读全文
Summary: Deep Copy vs. Shallow Copy vs. Lazy Copy
摘要:Object copyAnobject copyis an action in computing where a data object has itsattributescopied to another object of the same data type. Anobjectis a co...
阅读全文
Leetcode: Binary Tree Postorder Transversal
摘要:难度:70 recursive方法很直接: Iterative 最优做法: pre-order traversal is root-left-right. post-order traversal is left-right-root. We can modify pre-order travers
阅读全文
Leetcode: Binary Tree Inorder Transversal
摘要:recursive 方法: Iterative method: 参考了一下网上的思路,其实就是用一个栈来模拟递归的过程。所以算法时间复杂度也是O(n),空间复杂度是栈的大小O(logn)。
阅读全文
Leetcode: Reorder List && Summary: Reverse a LinkedList
摘要:这是一道比较综合的链表操作的题目,要按照题目要求给链表重新连接成要求的结果。其实理清思路也比较简单,分三步完成:(1)将链表切成两半,也就是找到中点,然后截成两条链表;(2)将后面一条链表进行reverse操作,就是反转过来;(3)将两条链表按顺序依次merge起来。 这几个操作都是我们曾经接触过的
阅读全文
Summary: Binary Search
摘要:Iterative ways: 1 int binarySearch (int[] a, int x) { 2 int low = 0; 3 int high = a.length - 1; 4 int mid; 5 6 while (low x) {12 ...
阅读全文
Leetcode: Single Number
摘要:Analysis: 需求里面要求O(N)时间以及无额外空间,这就排除了使用boolean array, hashmap这些个方法,只能在原数组上进行查找。O(N)基本上就相当于遍历数组. 最好的方法: 第二遍做法: 17行 & 运算符优先等级低于 == 所以一定要打括号 一样的思路另一个做法: 另外
阅读全文
Leetcode: Longest Palindromic Substring && Summary: Palindrome
摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Example 2: Analysis: 想到
阅读全文
Summary: Java中函数参数的传递
摘要:函数调用参数传递类型(java)的用法介绍.java方法中传值和传引用的问题是个基本问题,但是也有很多人一时弄不清。(一)基本数据类型:传值,方法不会改变实参的值。 1 public class TestFun { 2 3 public static void testInt(int ...
阅读全文
Summary: Depth-first Search(DFS)
摘要:There are generally two methods to write DFS algorithm, one is using recursion, another one is using stack. (reference from Wiki Pedia)Pseudocode for ...
阅读全文
浙公网安备 33010602011771号