Skip to content

Instantly share code, notes, and snippets.

View fishercoder1534's full-sized avatar

Fisher Coder fishercoder1534

View GitHub Profile

Oh my zsh.

Oh My Zsh

Install ZSH.

sudo apt install zsh-autosuggestions zsh-syntax-highlighting zsh

Install Oh my ZSH.

package multithread;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Worker implements Runnable {
public boolean running = false;
public Worker() {
# Compile: pregen/media.proto
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:828: error: cannot find symbol
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
^
symbol: class OneofDescriptor
location: class Descriptors
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:2669: error: cannot find symbol
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
^
symbol: class OneofDescriptor
# Compile: pregen/media.proto
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:11: error: Image is not abstract and does not override abstract method newBuilderForType(BuilderParent) in GeneratedMessage
public static final class Image extends
^
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:274: error: serializers.protobuf.media.MediaContentHolder.Image.Builder is not abstract and does not override abstract method internalGetFieldAccessorTable() in com.google.protobuf.GeneratedMessage.Builder
public static final class Builder extends
^
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:535: error: Media is not abstract and does not override abstract method newBuilderForType(BuilderParent) in GeneratedMessage
public static final class Media extends
^
public List<String> findWords(char[][] board, String[] words) {
TrieNode root = buildTrie(words);
List<String> result = new ArrayList();
for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[0].length; j++){
dfs(root, board, i, j, result);
}
}
//this is the most straightforward solution which uses O(mn) space
public void setZeroes(int[][] matrix) {
if(matrix == null || matrix.length == 0) return;
int height = matrix.length, width = matrix[0].length;
boolean[][] zero = new boolean[height][width];
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++){
if(matrix[i][j] == 0) zero[i][j] = true;
}
public int closestValue(TreeNode root, double target) {
long minVal = Long.MAX_VALUE;
while(root != null){
if(Math.abs(root.val - target) < Math.abs(minVal - target)){
minVal = root.val;
}
if(target < root.val) root = root.left;
else root = root.right;
}
public int closestValue(TreeNode root, double target) {
if(root == null) return 0;
return dfs(root, target, root.val);
}
private int dfs(TreeNode root, double target, int minVal) {
if (root == null)
return minVal;
if (Math.abs(root.val - target) < Math.abs(minVal - target)) {
//we can tailor the solution to use the BST feature: left subtrees are always smaller than the root the right subtrees
//this finished in 0 ms
public int closestValue(TreeNode root, double target) {
if(root == null) return 0;
return dfs(root, target, root.val);
}
private int dfs(TreeNode root, double target, int minVal) {
if(root == null) return minVal;
public int numWays(int n, int k) {
if(n == 0) return 0;
else if(n == 1) return k;
int sameColorCnt = k, diffColorCnt = k*(k-1);
for(int i = 2; i < n; i++){
int temp = diffColorCnt;
diffColorCnt = (diffColorCnt+sameColorCnt)*(k-1);
sameColorCnt = temp;
}