Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
- Dec 31 Sun 2017 13:03
-
Leetcode 283 @ Java
283. Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
- Dec 31 Sun 2017 01:55
-
Leetcode 29 @ Java
92. Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.
Reverse a linked list from position m to n. Do it in-place and in one-pass.
- Dec 30 Sat 2017 11:47
-
Leetcode Math 13 @ Java
13. Roman to Integer
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
- Dec 30 Sat 2017 07:26
-
Leetcode Tree 173, 285 @ Java
- Dec 29 Fri 2017 10:45
-
Leetcode 29 @ Java
29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.
If it is overflow, return MAX_INT.
Divide two integers without using multiplication, division and mod operator.
If it is overflow, return MAX_INT.
- Dec 29 Fri 2017 05:12
-
Leetcode BFS 33 @ Java
33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
- Dec 27 Wed 2017 08:37
-
Leetcode 3 @ Java
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given
Given
Given
這題不是用DP,因為一但遇到重疊的基本上counting是直接歸零
看解答也是用two pointer 掃過所有可能,l 負責記錄開頭,r 負責記錄結尾,
用兩個紀錄的好處是當要清除重複的字元時,前面非重複字元其實也要從set清除掉,
所以 l 可以幫助紀錄到底需要清掉哪些字元,中間過程中我們會掃過所有可能的不重複字串,
所以要有一個int 去記錄這之中最長的字串在最後return
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given
"abcabcbb", the answer is "abc", which the length is 3.Given
"bbbbb", the answer is "b", with the length of 1.Given
"pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequenceand not a substring.這題不是用DP,因為一但遇到重疊的基本上counting是直接歸零
看解答也是用two pointer 掃過所有可能,l 負責記錄開頭,r 負責記錄結尾,
用兩個紀錄的好處是當要清除重複的字元時,前面非重複字元其實也要從set清除掉,
所以 l 可以幫助紀錄到底需要清掉哪些字元,中間過程中我們會掃過所有可能的不重複字串,
所以要有一個int 去記錄這之中最長的字串在最後return
- Dec 26 Tue 2017 13:06
-
Leetcode Math 360 @ Java
- Oct 05 Thu 2017 09:33
-
Floyd's Cycle - Tortoise and Hare
通常用來detect loop,判斷從哪段開始有loop
解法可以想像是龜兔賽跑,兔子兩倍速,烏龜一倍速前進
假設c是起點距離loop的距離,k是起點距離第一次相遇點的距離,loop 長度是L
解法可以想像是龜兔賽跑,兔子兩倍速,烏龜一倍速前進
假設c是起點距離loop的距離,k是起點距離第一次相遇點的距離,loop 長度是L
- Oct 03 Tue 2017 03:08
-
Leetcode random 162,16 @ Java
162. Find Peak Element
A peak element is an element that is greater than its neighbors.
Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.
- Oct 03 Tue 2017 03:08
-
Leetcode Trie 211,208 @Java
211. Add and Search Word - Data structure design
Design a data structure that supports the following two operations:
void addWord(word)
bool search(word)
Design a data structure that supports the following two operations:
void addWord(word)
bool search(word)
- Sep 29 Fri 2017 11:29
-
java - covariant and invariant