Skip to content

Instantly share code, notes, and snippets.

View xnorcode's full-sized avatar
🛠️
building stuff

Andreas Ioannou xnorcode

🛠️
building stuff
View GitHub Profile
@xnorcode
xnorcode / Anagrams.java
Last active August 29, 2018 16:15
Anagrams Check with Array
...
static boolean isAnagram(String str1, String str2){
// not the same size its not anagram
if(str1.length() != str2.length()) return false;
// integer array of 26 for each letter of English alphabet
int[] letters = new int[26];
@xnorcode
xnorcode / ReverseStringWithStack.java
Last active August 29, 2018 16:14
Reversing a String using Stack in Java
...
// create a stack of characters
Stack<Character> st = new Stack<Character>();
// convert string to reverse into an array of characters
char[] arr = str.toCharArray();
// iterate chars array and push each char into the stack
for(char c : arr){
@xnorcode
xnorcode / ReverseStringWithArray.java
Last active August 29, 2018 16:14
Revesring a string with arrays
...
// convert String to array of chars
char[] s = str.toCharArray();
// get length of string
int n = s.length;
// get middle of string
int middle = n/2;
@xnorcode
xnorcode / TreeBreadthFirstSearch.java
Last active July 30, 2018 18:23
Check for path in a tree in a BFS method
...
// custom node class
public static class Node {
int id;
Node left;
Node right;
@xnorcode
xnorcode / LinkedListPrintAll.java
Last active May 3, 2018 21:10
Linked List Print All Nodes
public class LinkedList<T> {
// Reference to the head node
Node head;
public void printAll(){
// get reference to the head node
Node next = head;
@xnorcode
xnorcode / LinkedListNodeClass.java
Last active May 3, 2018 21:10
Linked List Node Class
public class LinkedList<T> {
// Reference to the head node
Node head;
// node class
class Node {
// Node data
T data;
@xnorcode
xnorcode / LinkedListHasCycle.java
Created May 3, 2018 19:23
Linked List Check For Cycle
public class LinkedList<T> {
// Reference to the head node
Node head;
public boolean hasCycle(){
// check if list empty
if(head == null) return false;
@xnorcode
xnorcode / LinkedListAddToHead.java
Last active May 3, 2018 19:08
Linked List Add Node To Head
public class LinkedList<T> {
// Reference to the head node
Node head;
public void addToHead(T data){
// create the new Node and add head as its next
Node newNode = new Node(data, head);
@xnorcode
xnorcode / LinkedListRemoveDuplicates.java
Created May 3, 2018 18:58
Linked List Remove Duplicate Nodes
public class LinkedList<T> {
// Reference to the head node
Node head;
public void removeDuplicates(){
// check if list empty
if(head == null) return;
@xnorcode
xnorcode / LinkedListRemoveNode.java
Created May 3, 2018 17:01
Linked List Remove Node
public class LinkedList<T> {
// Reference to the head node
Node head;
public void removeNode(T data){
// check if list empty
if(head == null) return;