Skip to content

Instantly share code, notes, and snippets.

<?php
// array for JSON response
$response = array();
// check for required fields
if (isset($_GET['name']) && isset($_GET['password'])) {
$name = $_GET['name'];
$message = $_GET['message'];
@dmnugent80
dmnugent80 / CondenseString.java
Created April 26, 2015 20:37
Condense String to character and count
public class CondenseString
{
public static void main(String[] args)
{
StringBuilder sb = new StringBuilder();
String test = "aaaabbbcccccccdeee";
char ch = test.charAt(0);
int count = 1;
@dmnugent80
dmnugent80 / GetLevelBST.java
Created April 7, 2015 01:55
Get Level of Element in Binary Search Tree
public class Main
{
public static void main(String[] args)
{
BinaryTree tree = new BinaryTree();
tree.add(20);
tree.add(10);
tree.add(30);
tree.add(15);
@dmnugent80
dmnugent80 / HasAnagrams.java
Last active August 29, 2015 14:16
String Array Has Anagrams
//second attempt, using HashSet and detecting collision
import java.util.Arrays;
import java.util.HashSet;
public class HasAnagrams
{
public static void main(String[] args)
{
String[] arr = {"bag", "bat", "tab"};
@dmnugent80
dmnugent80 / ConvertBinaryTreeToCircularLinkedList.java
Last active August 29, 2015 14:16
Convert Binary Tree to Circular Linked List
public class ConvertTreeToLinkedList
{
public static Node prev = null;
public static Node head = null;
public static void main(String[] args)
{
Node n1 = new Node(5);
@dmnugent80
dmnugent80 / MinUniqueCharactersString.java
Last active August 29, 2015 14:16
Min Unique Characters in String
import java.util.HashSet;
import java.util.HashMap;
public class MinUnique
{
public static void main(String[] args)
{
String str = "cabbcbcbbccaa";
HashSet<Character> set = new HashSet<Character>();
set.add('a');
@dmnugent80
dmnugent80 / StringMatchWithStars.java
Created March 8, 2015 18:17
String Match with Stars
//This is the brute force implementation
import java.util.HashSet;
public class MatchesWithStars
{
public static void main(String[] args)
{
HashSet<String> words = new HashSet<String>();
words.add("hello");
@dmnugent80
dmnugent80 / ContiguousSequenceSum.java
Created March 4, 2015 20:43
Given a sequence of positive integers A and an integer T, return whether there is a continuous sequence of A that sums up to exactly T
/*
Question: Given a sequence of positive integers A and an integer T, return whether there is a continuous sequence of A that sums up to exactly T
*/
public class SequenceSum
{
public static void main(String[] args)
{
@dmnugent80
dmnugent80 / ArrangeLargestNumber.java
Created March 2, 2015 05:31
Arrange Largest Number into String
public class Solution {
public String largestNumber(int[] num) {
String[] arr = new String[num.length];
for (int i = 0; i < num.length; i++){
arr[i] = Integer.toString(num[i]);
}
Comparator<String> comp = new Comparator<String>(){
@dmnugent80
dmnugent80 / MaxValidParentheses.java
Created March 2, 2015 04:34
Max Valid Parentheses
public class Solution {
public int longestValidParentheses(String s) {
Stack<Integer> stk = new Stack<Integer>();
int left = -1;
int maxCount = 0;
for (int i = 0; i < s.length(); i++){
if (s.charAt(i) == '('){
stk.push(i);
}
else{