Skip to content

Instantly share code, notes, and snippets.

public boolean checkUniqueness(String source) {
// Assumes that string includes ASCII characters (0-256)
if (source == null || source.length() == 0 || source.length() > 256) {
return false;
}
boolean[] seen = new boolean[256];
for (int i = 0; i < source.length(); i++) {
int temp = (int) source.charAt(i);
public boolean isPermutation(String source, String dest) {
// is source a permutation of dest?
if (source == null || dest == null)
return false;
if (source.length() != dest.length()
return false;
while (source.length() > 0) {
// If they somehow
class Node {
Node next = null;
char data;
public Node(char c) {
data = c;
}
}
// FOLLOW UP -> FOLW UP
public Node findLastKth(Node head, int k) {
// Assume k > 0
if (k <= 0 || head == null)
return null;
Node current = head;
Node runner = current;
while (k > 0 && runner != null) {
k--;
runner = runner.next;
public void fillZeros(int[][] matrix) {
int numRows = matrix.length;
int numCols = matrix[0].length;
boolean[] rows = new boolean[numRows];
boolean[] cols = new boolean[numCols];
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
if (matrix[i][j] == 0) {
public void partitionList(Node head, int value) {
Node small = null;
Node smallItr = null;
Node great = null;
Node greatItr;
while (head != null) {
if (head.data < value) {
if (smallItr == null) {
small = smallItr = head;
}
class Node {
Node next;
Node prev;
int data;
public Node(int value) {
this.data = value;
}
}
public class Node {
public Node next;
public Node nextMinimum;
public int data;
public Node(int value) {
this.data = value;
}
}
public class StackWithMin extends Stack<Integer> {
Stack<Integer> minStack;
private int minValue;
public StackWithMin() {
super();
minStack = new Stack<Integer>();
}
@berkayk
berkayk / 0_reuse_code.js
Created July 26, 2017 07:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console