Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
dmnugent80 / ReverseSentence.java
Last active August 29, 2015 14:14
Reverse Sentence
import java.lang.Math;
import java.util.*;
// our main class becomes a file but the main method is still found
public class HelloWorld
{
public static void main(String[] args)
{
ReverseSentence myObject = new ReverseSentence();
String reversed = myObject.reverseString("Hello,, . , I would, like to reverse. . this. sentence, and another thing. Thank You.");
@dmnugent80
dmnugent80 / BinaryTreeCount.java
Last active August 29, 2015 14:14
Get Count of value in Binary Tree
/*
Interview Question:
Here's a binary tree: write a function to return the count of a certain value in the tree
*/
public class TreeNode{
int data;
TreeNode left;
TreeNode right;
@dmnugent80
dmnugent80 / FizzBuzz.java
Created January 30, 2015 23:20
FizzBuzz
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
@dmnugent80
dmnugent80 / ReverseLinkedListRecursive.java
Created February 1, 2015 09:20
Reverse Linked List Recursive
public class LinkedList
{
public static ListNode head = null;
public static void main(String[] args)
{
head = new ListNode(1);
@dmnugent80
dmnugent80 / binarySwap.java
Created February 1, 2015 23:59
Binary XOR Swap int values
int x=10;
int y=25;
System.out.println("x= " + x + " y = " + y);
x ^= (y ^= x);
y ^= x;
System.out.println("x= " + x + " y = " + y);
@dmnugent80
dmnugent80 / HeapSort.java
Created February 4, 2015 20:40
Heap Sort
public class HeapSort {
private static int getLeft(int index) {
return index * 2 + 1;
}
private static int getRight(int index) {
return index * 2 + 2;
}
private static void exchange (int[] arr, int first, int second) {
@dmnugent80
dmnugent80 / PrintKthElementBST.java
Last active August 29, 2015 14:14
Binary Search Tree Print Kth Element
public class Main
{
public static void main(String[] args)
{
BinaryTree tree = new BinaryTree();
tree.add(5);
tree.add(4);
tree.add(6);
tree.add(3);
@dmnugent80
dmnugent80 / MultiplesThreeAndFive.java
Created February 7, 2015 22:17
Sum Multiples of Thee and Five
public class Main
{
public static void main(String[] args)
{
MultiplesThreeAndFive myObject = new MultiplesThreeAndFive();
int sum = myObject.getSum(1000);
System.out.print("sum: " + sum);
}
@dmnugent80
dmnugent80 / EvenFib.java
Last active August 29, 2015 14:14
Sum of Even Fibonacci Numbers
public class Main
{
public static void main(String[] args)
{
EvenFib myObject = new EvenFib();
int sum = myObject.getEvenFibSum(4000000);
System.out.print("sum: " + sum);
}
}
@dmnugent80
dmnugent80 / LargestPrimeFactor.java
Last active March 14, 2021 06:39
Find Larget Prime Factor
public class Test
{
public static void main(String[] args)
{
LargestPrimeFactor myObject = new LargestPrimeFactor();
long largestPrimeFactor = myObject.largestPrimeFactor(600851475143L);
System.out.println("largest prime Factor: " + largestPrimeFactor);
}
}