Skip to content

Instantly share code, notes, and snippets.

View shixiaoyu's full-sized avatar
💭
Hello World :)

Xiaoyu shixiaoyu

💭
Hello World :)
View GitHub Profile
@shixiaoyu
shixiaoyu / google-docs-copy.js
Created January 22, 2023 01:43 — forked from Snarp/google-docs-copy.js
Script to allow copying from a protected Google Doc
/*
<https://stackoverflow.com/questions/40296831/is-it-possible-to-force-a-copy-of-a-protected-google-doc>
NOTE - 2021-05-24
-----------------
The script below isn't the fastest way to copy-and-paste from a protected
Google Doc. Before trying it, I'd suggest following MikoFrosty's advice from
the comments:
@shixiaoyu
shixiaoyu / 2353.java
Last active September 18, 2022 18:48
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
public class FoodRatings {
private class Food implements Comparable<Food>{
// skip boilerplate getter/setters
public String food;
public int minPathCost(int[][] grid, int[][] moveCost) {
if (grid == null || grid.length == 0 || grid[0] == null || grid[0].length == 0 || moveCost == null) {
return -1; // or throw exception
}
int[][] minCost = new int[grid.length][grid[0].length];
for (int i = 0; i < minCost[0].length; i++) {
minCost[0][i] = grid[0][i]; // first row costs are the init values
}
public double angleClock(int hour, int minutes) {
if (hour == 12) {
hour = 0;
}
double angle = Math.abs(minutes * 6 - (hour + (double)minutes / 60) * 30);
if (angle > 180) {
angle = 360 - angle;
}
return angle;
public int numIdenticalPairsWithSort(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
Arrays.sort(nums);
int goodPairsCount = 0;
int start = 0;
int end = 0;
public int numIdenticalPairs(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
// key: int value; value: number of occurrence
Map<Integer, Integer> lookup = new HashMap<>();
int goodPairsCount = 0;
for (int i : nums) {
if (lookup.containsKey(i)) {
public int rob(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
if (nums.length == 1) {
return nums[0];
}
// rob first house, so need to remove the last house
int[] rob_first_nums = new int[nums.length - 1];
public int rob(int[] num) {
if (num == null || num.length == 0) {
return 0;
}
int n = num.length;
int[] lookup = new int[n + 1]; // DP array size normally larger than 1
lookup[0] = 0;
lookup[1] = num[0];
private class DisjointSet {
private Map<String, String> lookup = new HashMap<>();
public void init(int row, int col) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
String key = i + "," + j;
// initially key value is the same, meaning the parent of the disjoint set is itself, i.e., isolated or not initialized
this.lookup.put(key, key);
}
private final int[] xDirection = {1, 0, -1, 0};
private final int[] yDirection = {0, -1, 0, 1 };
public int numIslands(char[][] grid) {
if (grid == null || grid.length == 0 || grid[0].length == 0) {
return 0;
}
int m = grid.length;
int n = grid[0].length;