This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// array for JSON response | |
$response = array(); | |
// check for required fields | |
if (isset($_GET['name']) && isset($_GET['password'])) { | |
$name = $_GET['name']; | |
$message = $_GET['message']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CondenseString | |
{ | |
public static void main(String[] args) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
String test = "aaaabbbcccccccdeee"; | |
char ch = test.charAt(0); | |
int count = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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"}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConvertTreeToLinkedList | |
{ | |
public static Node prev = null; | |
public static Node head = null; | |
public static void main(String[] args) | |
{ | |
Node n1 = new Node(5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{ |