This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int firstMissingPositive(int[] nums) { | |
for (int i = 0; i < nums.length; ++i) { | |
if (nums[i] == i + 1) { | |
continue; | |
} | |
int n = nums[i]; | |
nums[i] = -1; | |
while (n > 0 && n <= nums.length && nums[n - 1] != n) { | |
int t = nums[n - 1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { val = x; } | |
* } | |
*/ | |
class Solution { | |
public ListNode deleteDuplicates(ListNode head) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { | |
* val = x; | |
* next = null; | |
* } | |
* } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { val = x; } | |
* } | |
*/ | |
class Solution { | |
public ListNode deleteDuplicates(ListNode head) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://leetcode.com/problems/score-after-flipping-matrix/description/ | |
// Solution: Greedy. | |
// It is always good to make first column all 1s, because it is the most significant bit. | |
// And for other columns, flip if it gives larger result. | |
// Correctness: We only need to prove it is optimal for 2-columns matrix. | |
// Though I don't havr formal proof, we can think about any counter cases: | |
// is there a case that for a row starting with 0, and we don't flip the row? | |
// O(R*C) time. | |
import java.util.*; | |
class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package leetcode.repeatedStringMatch; | |
/** | |
* Created by siyao on 9/30/17. | |
* https://leetcode.com/contest/leetcode-weekly-contest-52/problems/repeated-string-match/ | |
* Solution: | |
* There are just few cases. Then at some point of repeating, if B is still not a substring, | |
* then we can just stop. So the key is to find the "point", t and t + 1. | |
* | |
* Thinking: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package leetcode.longestUnivaluePath; | |
import ds.*; | |
/** | |
* Created by siyao on 9/30/17. | |
* https://leetcode.com/contest/leetcode-weekly-contest-52/problems/longest-univalue-path/ | |
* Solution: | |
* This does not sound like an easy level question. | |
* It is not easy to come up with the correct induction or sub-problem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Amour", | |
"url": "http://www.metacritic.com/movie/amour", | |
"rlsdate": "2012-12-19", | |
"score": "94", | |
"summary": "Georges and Anne are in their eighties. They are cultivated, retired music teachers. Their daughter, who is also a musician, lives abroad with her family. One day, Anne has an attack. The couple's...", | |
"rating": "PG-13", | |
"cast": "Emmanuelle Riva, Isabelle Huppert, Jean-Louis Trintignant", | |
"genre": "Drama, Romance", | |
"avguserscore": "8.0", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"A Girl Walks Home Alone at Night", | |
"url":"http://www.metacritic.com/movie/a-girl-walks-home-alone-at-night", | |
"rlsdate":"2014-11-21", | |
"score":"81", | |
"summary":"In the Iranian ghost-town Bad City, a place that reeks of death and loneliness, the townspeople are unaware they are being stalked by a lonesome vampire.", | |
"rating":"Not Rated", | |
"cast":"", | |
"genre":"Thriller, Horror, Romance", | |
"avguserscore":"7.2", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rc": [ | |
{ | |
"name": "The Babadook", | |
"url": "http://www.metacritic.com/movie/the-babadook", | |
"rlsdate": "2014-11-28", | |
"score": "86", | |
"summary": "Six years after the violent death of her husband, Amelia (Essie Davis) is at a loss. She struggles to discipline her ‘out of control’ 6 year-old, Samuel (Noah Wiseman), a son she finds impossible...", | |
"rating": "Not Rated", | |
"cast": "Barbara West, Daniel Henshall, Essie Davis, Hayley McElhinney, Noah Wiseman", |
NewerOlder