Skip to content

Instantly share code, notes, and snippets.

View Anirudhk94's full-sized avatar

Anirudh Kulkarni Anirudhk94

  • Oracle
  • Seattle, WA
View GitHub Profile
@Anirudhk94
Anirudhk94 / UnionFind.java
Created October 8, 2018 03:23
Union Find
class UnionFind {
public int[] rank;
public int[] parent;
public int n;
public UnionFind(int n){
this.n = n;
rank = new int[n];
parent = new int[n];
for(int i = 0 ; i < n ; i++)
@Anirudhk94
Anirudhk94 / gist:c3fd5d939f2f03e345bfabab50348010
Created January 11, 2019 01:23
[React] Increment Button Label On Click
class Button extends React.Component {
state = {counter : 0};
changeLabel = () => {
this.setState({
counter: this.state.counter + 1
})
}
render() {
class Button extends React.Component {
//prevState to avoid race condition
state = {counter : 0};
changeLabel = () => {
this.setState((prevState) => {
return {
counter: prevState.counter + 1
}
})
}
class Button extends React.Component {
render() {
return(
<button onClick={this.props.onClickFunction}>
Plus One
</button>
)
}
}
//https://jscomplete.com/playground/xs204018
class Button extends React.Component {
handleInc = () => {
this.props.onClickFunction(this.props.incValue)
}
render() {
return(
<button onClick={this.handleInc}>
+{this.props.incValue}
</button>
const Card = (props) => {
return(
<div style={{margin : '1em'}}>
<img width ='75' src={props.avatar_url} />
<div style={{display : 'inline-block', marginLeft : 10}}>
<div style={{fontSize : '1.25em', fontWeight : 'bold'}}>{props.name}</div>
<div>{props.company}</div>
</div>
</div>
)
from collections import defaultdict
from collections import deque
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
class Solution {
public int subarraySum(int[] nums, int k) {
int sum = 0;
int result = 0;
HashMap<Integer, Integer> prevSum = new HashMap<Integer, Integer>();
prevSum.put(0, 1);
for(int i = 0 ; i < nums.length ; i++) {
sum += nums[i];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<title>JS Bin</title>
</head>
<body>