Skip to content

Instantly share code, notes, and snippets.

View forkercat's full-sized avatar
🉑
一杯咖啡、一只猫

Junhao Wang forkercat

🉑
一杯咖啡、一只猫
View GitHub Profile
@forkercat
forkercat / cloudSettings
Last active March 28, 2019 01:46
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-03-28T01:46:10.783Z","extensionVersion":"v3.2.7"}
import java.util.ArrayList;
import java.util.List;
/**
* Main
*/
public class Main {
public static void main(String[] args) {
Class<Number> strClz = N2umber.class;
Class<Integer> intClz = Integer.class;
@forkercat
forkercat / IntList.java
Last active March 31, 2019 02:37
recursive version of catenate
public class IntList {
public int first;
public IntList rest;
public IntList(int first0, IntList rest0) {
first = first0;
rest = rest0;
}
/**
@forkercat
forkercat / SLList_Sentinel.java
Created April 1, 2019 02:31
Sentinel problem?
/**
* Created by JunhaoW on 03/31/2019
*/
public class SLList_Sentinel {
private int size;
private IntNode sentinel; /* The first item (if it exists) is at sentinel.next */
/* sentinel should not be changed later (after init) */
public SLList_Sentinel() {
import java.util.ArrayList;
import java.util.List;
/**
* Created by JunhaoW on 05/06/2019
*/
public class MyBTree<Key extends Comparable<Key>, Value> {
/**
* 2-3 tree: Order-of-3, 3 children max
@forkercat
forkercat / Solution.java
Created September 15, 2019 22:54
Permutaitons
class Solution {
public List<List<Integer>> permute(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
permute(0, nums, result);
return result;
}
private void permute(int depth, int[] nums, List<List<Integer>> result) {
// base case
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
List<Integer> numList = new ArrayList<>();
result.add(new ArrayList<>()); // empty set
subsets(0, nums, numList, result);
return result;
}
private void subsets(int offset, int[] nums, List<Integer> numList, List<List<Integer>> result) {
public class BuyAndSellStock {
/**
* Brute-Force
* Time: O(N^2)
*/
public static double maxProfitBruteForce(List<Double> prices) {
double maxProfit = 0.0;
for (int i = 0; i < prices.size(); ++i) {
for (int j = i; j < prices.size(); ++j) {
@forkercat
forkercat / MaxStack.java
Created October 18, 2019 06:56
not correct~
class Solution {
class ListNode {
int val;
ListNode oldNode = null; // point to old max node
ListNode prev = null;
ListNode next = null;
ListNode(int _val) { val = _val; }
}
ListNode dummy = new ListNode(0);
@forkercat
forkercat / ReverseLinkedList.java
Created October 19, 2019 08:48
ReverseLinkedList
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {