Skip to content

Instantly share code, notes, and snippets.

View Staticity's full-sized avatar

Jaime Rivera Staticity

View GitHub Profile
@Staticity
Staticity / StateSpacePath.java
Last active October 2, 2018 05:15
BFS and Recursive DFS for finding the path from 'start' to 'end' nodes.
import java.util.Map;
import java.util.HashMap;
import java.util.Queue;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
@Staticity
Staticity / LevelOrderBFS.java
Last active September 11, 2015 18:07
Four ways to do Level Order BFS. They're ordered from worst (A) to best (D) based on Jaime's preferences.
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Queue;
import java.util.LinkedList;
import java.util.List;
@Staticity
Staticity / StateSpaceSearch.java
Last active June 9, 2023 04:35
Examples of Breadth-First Search (BFS) and Depth-First Search (DFS)
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
@Staticity
Staticity / StringBuildReverse.java
Created September 10, 2015 02:22
Example of StringBuilder's reverse() function.
import java.util.*;
public class StringBuildReverse
{
public static void main(String args[])
{
String s = "test";
StringBuilder sb = new StringBuilder(s);
StringBuilder sbR = sb.reverse();
import java.util.Scanner;
import java.util.List;
public class Solution
{
public static void main(String args[])
{
// Construct a Scanner with the argument System.in to read from
// standard input.
Scanner scan = new Scanner(System.in);
@Staticity
Staticity / cpp_example.cpp
Last active September 1, 2015 14:21
How to perform IO for C++ in Codeforces.
#include <iostream>
// So I don't have to include "std::" every time...
using namespace std;
int main()
{
// Declare the variable you wish to read into...
int apples;
@Staticity
Staticity / JavaExample.java
Created September 1, 2015 04:19
How to perform IO for Java in Codeforces.
import java.util.Scanner;
public class Solution
{
public static void main(String args[])
{
// Construct a Scanner with the argument System.in to read from
// standard input.
Scanner scan = new Scanner(System.in);
@Staticity
Staticity / rotated_sorted_array.cc
Created May 29, 2015 07:45
Rotated Sorted Array
#include <iostream>
#include <vector>
using namespace std;
class Solution {
int find(vector<int>& nums, int start, int end, int target)
{
int lo = start, hi = end, mid;
bool safe(int grid[9][9], int row, int col)
{
for (int i = 0; i < 9; ++i)
{
if (i != col && grid[row][i] == grid[row][col])
{
return false;
}
}
@Staticity
Staticity / permutation_substring.cc
Created November 9, 2014 23:42
Given a list of characters, find shortest substring in a string that contains all of those characters.
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
void accumulateIndices(string container, string c, vector<int>& positions)