mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-05 16:27:33 +08:00
style: enable HideUtilityClassConstructor
in checkstyle (#5147)
This commit is contained in:
@ -175,7 +175,7 @@
|
|||||||
<!-- See https://checkstyle.org/checks/design/index.html -->
|
<!-- See https://checkstyle.org/checks/design/index.html -->
|
||||||
<!-- TODO <module name="DesignForExtension"/> -->
|
<!-- TODO <module name="DesignForExtension"/> -->
|
||||||
<!-- TODO <module name="FinalClass"/> -->
|
<!-- TODO <module name="FinalClass"/> -->
|
||||||
<!-- TODO <module name="HideUtilityClassConstructor"/> -->
|
<module name="HideUtilityClassConstructor"/>
|
||||||
<module name="InterfaceIsType"/>
|
<module name="InterfaceIsType"/>
|
||||||
<!-- TODO <module name="VisibilityModifier"/> -->
|
<!-- TODO <module name="VisibilityModifier"/> -->
|
||||||
|
|
||||||
|
@ -7,7 +7,9 @@ import java.util.TreeSet;
|
|||||||
* Finds all permutations of 1...n of length k
|
* Finds all permutations of 1...n of length k
|
||||||
* @author TheClerici (<a href="https://github.com/TheClerici">git-TheClerici</a>)
|
* @author TheClerici (<a href="https://github.com/TheClerici">git-TheClerici</a>)
|
||||||
*/
|
*/
|
||||||
public class ArrayCombination {
|
public final class ArrayCombination {
|
||||||
|
private ArrayCombination() {
|
||||||
|
}
|
||||||
private static int length;
|
private static int length;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,9 @@ import java.util.TreeSet;
|
|||||||
* Finds all permutations of given array
|
* Finds all permutations of given array
|
||||||
* @author Alan Piao (<a href="https://github.com/cpiao3">git-Alan Piao</a>)
|
* @author Alan Piao (<a href="https://github.com/cpiao3">git-Alan Piao</a>)
|
||||||
*/
|
*/
|
||||||
public class Combination {
|
public final class Combination {
|
||||||
|
private Combination() {
|
||||||
|
}
|
||||||
|
|
||||||
private static int length;
|
private static int length;
|
||||||
|
|
||||||
|
@ -26,7 +26,9 @@ import java.util.List;
|
|||||||
51 46 55 44 53 4 21 12
|
51 46 55 44 53 4 21 12
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class KnightsTour {
|
public final class KnightsTour {
|
||||||
|
private KnightsTour() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final int BASE = 12;
|
private static final int BASE = 12;
|
||||||
private static final int[][] MOVES = {
|
private static final int[][] MOVES = {
|
||||||
|
@ -14,7 +14,9 @@ class Node {
|
|||||||
Set<Integer> edges = new HashSet<Integer>();
|
Set<Integer> edges = new HashSet<Integer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MColoring {
|
public final class MColoring {
|
||||||
|
private MColoring() {
|
||||||
|
}
|
||||||
static int possiblePaint(ArrayList<Node> nodes, int n, int m) {
|
static int possiblePaint(ArrayList<Node> nodes, int n, int m) {
|
||||||
|
|
||||||
// Create a visited array of n nodes
|
// Create a visited array of n nodes
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.thealgorithms.backtracking;
|
package com.thealgorithms.backtracking;
|
||||||
|
|
||||||
public class MazeRecursion {
|
public final class MazeRecursion {
|
||||||
|
private MazeRecursion() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void mazeRecursion() {
|
public static void mazeRecursion() {
|
||||||
// First create a 2 dimensions array to mimic a maze map
|
// First create a 2 dimensions array to mimic a maze map
|
||||||
|
@ -32,7 +32,9 @@ import java.util.List;
|
|||||||
* queen is not placed safely. If there is no such way then return an empty list
|
* queen is not placed safely. If there is no such way then return an empty list
|
||||||
* as solution
|
* as solution
|
||||||
*/
|
*/
|
||||||
public class NQueens {
|
public final class NQueens {
|
||||||
|
private NQueens() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
placeQueens(1);
|
placeQueens(1);
|
||||||
|
@ -7,7 +7,9 @@ import java.util.List;
|
|||||||
* Finds all permutations of given array
|
* Finds all permutations of given array
|
||||||
* @author Alan Piao (<a href="https://github.com/cpiao3">Git-Alan Piao</a>)
|
* @author Alan Piao (<a href="https://github.com/cpiao3">Git-Alan Piao</a>)
|
||||||
*/
|
*/
|
||||||
public class Permutation {
|
public final class Permutation {
|
||||||
|
private Permutation() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all permutations of given array using backtracking
|
* Find all permutations of given array using backtracking
|
||||||
|
@ -5,7 +5,9 @@ package com.thealgorithms.bitmanipulation;
|
|||||||
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class IndexOfRightMostSetBit {
|
public final class IndexOfRightMostSetBit {
|
||||||
|
private IndexOfRightMostSetBit() {
|
||||||
|
}
|
||||||
public static int indexOfRightMostSetBit(int n) {
|
public static int indexOfRightMostSetBit(int n) {
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return -1; // No set bits
|
return -1; // No set bits
|
||||||
|
@ -5,7 +5,9 @@ package com.thealgorithms.bitmanipulation;
|
|||||||
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class IsEven {
|
public final class IsEven {
|
||||||
|
private IsEven() {
|
||||||
|
}
|
||||||
public static boolean isEven(int number) {
|
public static boolean isEven(int number) {
|
||||||
return (number & 1) == 0;
|
return (number & 1) == 0;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ package com.thealgorithms.bitmanipulation;
|
|||||||
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class IsPowerTwo {
|
public final class IsPowerTwo {
|
||||||
|
private IsPowerTwo() {
|
||||||
|
}
|
||||||
public static boolean isPowerTwo(int number) {
|
public static boolean isPowerTwo(int number) {
|
||||||
if (number <= 0) {
|
if (number <= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -5,7 +5,9 @@ package com.thealgorithms.bitmanipulation;
|
|||||||
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class NonRepeatingNumberFinder {
|
public final class NonRepeatingNumberFinder {
|
||||||
|
private NonRepeatingNumberFinder() {
|
||||||
|
}
|
||||||
|
|
||||||
public static int findNonRepeatingNumber(int[] arr) {
|
public static int findNonRepeatingNumber(int[] arr) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -5,7 +5,9 @@ package com.thealgorithms.bitmanipulation;
|
|||||||
* @author Bama Charan Chhandogi
|
* @author Bama Charan Chhandogi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class NumbersDifferentSigns {
|
public final class NumbersDifferentSigns {
|
||||||
|
private NumbersDifferentSigns() {
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean differentSigns(int num1, int num2) {
|
public static boolean differentSigns(int num1, int num2) {
|
||||||
return (num1 ^ num2) < 0;
|
return (num1 ^ num2) < 0;
|
||||||
|
@ -5,7 +5,9 @@ package com.thealgorithms.bitmanipulation;
|
|||||||
* @author Bama Charan Chhandogi
|
* @author Bama Charan Chhandogi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ReverseBits {
|
public final class ReverseBits {
|
||||||
|
private ReverseBits() {
|
||||||
|
}
|
||||||
|
|
||||||
public static int reverseBits(int n) {
|
public static int reverseBits(int n) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -7,7 +7,9 @@ import java.util.Scanner;
|
|||||||
* This class is build to demonstrate the application of the AES-algorithm on a
|
* This class is build to demonstrate the application of the AES-algorithm on a
|
||||||
* single 128-Bit block of data.
|
* single 128-Bit block of data.
|
||||||
*/
|
*/
|
||||||
public class AES {
|
public final class AES {
|
||||||
|
private AES() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Precalculated values for x to the power of 2 in Rijndaels galois field.
|
* Precalculated values for x to the power of 2 in Rijndaels galois field.
|
||||||
|
@ -17,7 +17,9 @@ import javax.crypto.spec.GCMParameterSpec;
|
|||||||
* hence in the following program we display it in hexadecimal format of the
|
* hence in the following program we display it in hexadecimal format of the
|
||||||
* underlying bytes.
|
* underlying bytes.
|
||||||
*/
|
*/
|
||||||
public class AESEncryption {
|
public final class AESEncryption {
|
||||||
|
private AESEncryption() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||||
private static Cipher aesCipher;
|
private static Cipher aesCipher;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.thealgorithms.ciphers;
|
package com.thealgorithms.ciphers;
|
||||||
|
|
||||||
class AffineCipher {
|
final class AffineCipher {
|
||||||
|
private AffineCipher() {
|
||||||
|
}
|
||||||
|
|
||||||
// Key values of a and b
|
// Key values of a and b
|
||||||
static int a = 17;
|
static int a = 17;
|
||||||
|
@ -7,7 +7,9 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* @author <a href="https://github.com/freitzzz">freitzzz</a>
|
* @author <a href="https://github.com/freitzzz">freitzzz</a>
|
||||||
*/
|
*/
|
||||||
public class ColumnarTranspositionCipher {
|
public final class ColumnarTranspositionCipher {
|
||||||
|
private ColumnarTranspositionCipher() {
|
||||||
|
}
|
||||||
|
|
||||||
private static String keyword;
|
private static String keyword;
|
||||||
private static Object[][] table;
|
private static Object[][] table;
|
||||||
|
@ -11,7 +11,9 @@ import java.util.Scanner;
|
|||||||
* for encryption. The cipher key and plaintext/ciphertext are user inputs.
|
* for encryption. The cipher key and plaintext/ciphertext are user inputs.
|
||||||
* @author Ojasva Jain
|
* @author Ojasva Jain
|
||||||
*/
|
*/
|
||||||
public class HillCipher {
|
public final class HillCipher {
|
||||||
|
private HillCipher() {
|
||||||
|
}
|
||||||
|
|
||||||
static Scanner userInput = new Scanner(System.in);
|
static Scanner userInput = new Scanner(System.in);
|
||||||
|
|
||||||
|
@ -13,7 +13,9 @@ package com.thealgorithms.ciphers;
|
|||||||
* @author Hikmet ÇAKIR
|
* @author Hikmet ÇAKIR
|
||||||
* @since 08-07-2022+03:00
|
* @since 08-07-2022+03:00
|
||||||
*/
|
*/
|
||||||
public class Polybius {
|
public final class Polybius {
|
||||||
|
private Polybius() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final char[][] KEY = {
|
private static final char[][] KEY = {
|
||||||
// 0 1 2 3 4
|
// 0 1 2 3 4
|
||||||
|
@ -2,7 +2,9 @@ package com.thealgorithms.ciphers;
|
|||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
class ProductCipher {
|
final class ProductCipher {
|
||||||
|
private ProductCipher() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try (Scanner sc = new Scanner(System.in)) {
|
try (Scanner sc = new Scanner(System.in)) {
|
||||||
|
@ -7,7 +7,9 @@ package com.thealgorithms.ciphers.a5;
|
|||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
public class Utils {
|
public final class Utils {
|
||||||
|
private Utils() {
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean increment(BitSet bits, int size) {
|
public static boolean increment(BitSet bits, int size) {
|
||||||
int i = size - 1;
|
int i = size - 1;
|
||||||
|
@ -13,7 +13,9 @@ import java.util.Scanner;
|
|||||||
* @author Michael Rolland
|
* @author Michael Rolland
|
||||||
* @version 2017.10.10
|
* @version 2017.10.10
|
||||||
*/
|
*/
|
||||||
public class AnyBaseToAnyBase {
|
public final class AnyBaseToAnyBase {
|
||||||
|
private AnyBaseToAnyBase() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smallest and largest base you want to accept as valid input
|
* Smallest and largest base you want to accept as valid input
|
||||||
|
@ -4,7 +4,9 @@ package com.thealgorithms.conversions;
|
|||||||
* @author Varun Upadhyay (<a href="https://github.com/varunu28">...</a>)
|
* @author Varun Upadhyay (<a href="https://github.com/varunu28">...</a>)
|
||||||
*/
|
*/
|
||||||
// Driver program
|
// Driver program
|
||||||
public class AnyBaseToDecimal {
|
public final class AnyBaseToDecimal {
|
||||||
|
private AnyBaseToDecimal() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
assert convertToDecimal("1010", 2) == Integer.valueOf("1010", 2);
|
assert convertToDecimal("1010", 2) == Integer.valueOf("1010", 2);
|
||||||
|
@ -6,7 +6,9 @@ import java.util.Scanner;
|
|||||||
// number.
|
// number.
|
||||||
// sn ,sb,db ---> ()dn . this is what we have to do .
|
// sn ,sb,db ---> ()dn . this is what we have to do .
|
||||||
|
|
||||||
public class AnytoAny {
|
public final class AnytoAny {
|
||||||
|
private AnytoAny() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scn = new Scanner(System.in);
|
Scanner scn = new Scanner(System.in);
|
||||||
|
@ -5,7 +5,9 @@ import java.util.Scanner;
|
|||||||
/**
|
/**
|
||||||
* This class converts a Binary number to a Decimal number
|
* This class converts a Binary number to a Decimal number
|
||||||
*/
|
*/
|
||||||
class BinaryToDecimal {
|
final class BinaryToDecimal {
|
||||||
|
private BinaryToDecimal() {
|
||||||
|
}
|
||||||
|
|
||||||
public static long binaryToDecimal(long binNum) {
|
public static long binaryToDecimal(long binNum) {
|
||||||
long binCopy, d, s = 0, power = 0;
|
long binCopy, d, s = 0, power = 0;
|
||||||
|
@ -8,7 +8,9 @@ import java.util.Scanner;
|
|||||||
*
|
*
|
||||||
* @author Nishita Aggarwal
|
* @author Nishita Aggarwal
|
||||||
*/
|
*/
|
||||||
public class BinaryToHexadecimal {
|
public final class BinaryToHexadecimal {
|
||||||
|
private BinaryToHexadecimal() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method converts a binary number to a hexadecimal number.
|
* This method converts a binary number to a hexadecimal number.
|
||||||
|
@ -7,7 +7,9 @@ import java.util.Scanner;
|
|||||||
*
|
*
|
||||||
* @author Zachary Jones
|
* @author Zachary Jones
|
||||||
*/
|
*/
|
||||||
public class BinaryToOctal {
|
public final class BinaryToOctal {
|
||||||
|
private BinaryToOctal() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main method
|
* Main method
|
||||||
|
@ -8,7 +8,9 @@ import java.util.ArrayList;
|
|||||||
* @author Varun Upadhyay (<a href="https://github.com/varunu28">...</a>)
|
* @author Varun Upadhyay (<a href="https://github.com/varunu28">...</a>)
|
||||||
*/
|
*/
|
||||||
// Driver Program
|
// Driver Program
|
||||||
public class DecimalToAnyBase {
|
public final class DecimalToAnyBase {
|
||||||
|
private DecimalToAnyBase() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
@ -5,7 +5,9 @@ import java.util.Scanner;
|
|||||||
/**
|
/**
|
||||||
* This class converts a Decimal number to a Binary number
|
* This class converts a Decimal number to a Binary number
|
||||||
*/
|
*/
|
||||||
class DecimalToBinary {
|
final class DecimalToBinary {
|
||||||
|
private DecimalToBinary() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Method
|
* Main Method
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.thealgorithms.conversions;
|
package com.thealgorithms.conversions;
|
||||||
|
|
||||||
// hex = [0 - 9] -> [A - F]
|
// hex = [0 - 9] -> [A - F]
|
||||||
class DecimalToHexaDecimal {
|
final class DecimalToHexaDecimal {
|
||||||
|
private DecimalToHexaDecimal() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final int SIZE_OF_INT_IN_HALF_BYTES = 8;
|
private static final int SIZE_OF_INT_IN_HALF_BYTES = 8;
|
||||||
private static final int NUMBER_OF_BITS_IN_HALF_BYTE = 4;
|
private static final int NUMBER_OF_BITS_IN_HALF_BYTE = 4;
|
||||||
|
@ -5,7 +5,9 @@ import java.util.Scanner;
|
|||||||
/**
|
/**
|
||||||
* This class converts Decimal numbers to Octal Numbers
|
* This class converts Decimal numbers to Octal Numbers
|
||||||
*/
|
*/
|
||||||
public class DecimalToOctal {
|
public final class DecimalToOctal {
|
||||||
|
private DecimalToOctal() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Method
|
* Main Method
|
||||||
|
@ -7,7 +7,9 @@ import java.util.Scanner;
|
|||||||
*
|
*
|
||||||
* @author Tanmay Joshi
|
* @author Tanmay Joshi
|
||||||
*/
|
*/
|
||||||
public class HexToOct {
|
public final class HexToOct {
|
||||||
|
private HexToOct() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method converts a Hexadecimal number to a decimal number
|
* This method converts a Hexadecimal number to a decimal number
|
||||||
|
@ -2,7 +2,9 @@ package com.thealgorithms.conversions;
|
|||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class HexaDecimalToDecimal {
|
public final class HexaDecimalToDecimal {
|
||||||
|
private HexaDecimalToDecimal() {
|
||||||
|
}
|
||||||
|
|
||||||
// convert hexadecimal to decimal
|
// convert hexadecimal to decimal
|
||||||
public static int getHexaToDec(String hex) {
|
public static int getHexaToDec(String hex) {
|
||||||
|
@ -7,7 +7,9 @@ package com.thealgorithms.conversions;
|
|||||||
* ('I', 1); ('IV',4); ('V', 5); ('IX',9); ('X', 10); ('XL',40); ('L', 50);
|
* ('I', 1); ('IV',4); ('V', 5); ('IX',9); ('X', 10); ('XL',40); ('L', 50);
|
||||||
* ('XC',90); ('C', 100); ('D', 500); ('M', 1000);
|
* ('XC',90); ('C', 100); ('D', 500); ('M', 1000);
|
||||||
*/
|
*/
|
||||||
public class IntegerToRoman {
|
public final class IntegerToRoman {
|
||||||
|
private IntegerToRoman() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final int[] ALL_ROMAN_NUMBERS_IN_ARABIC = new int[] {
|
private static final int[] ALL_ROMAN_NUMBERS_IN_ARABIC = new int[] {
|
||||||
1000,
|
1000,
|
||||||
|
@ -6,7 +6,9 @@ package com.thealgorithms.conversions;
|
|||||||
* @author Bama Charan Chhandogi
|
* @author Bama Charan Chhandogi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class OctalToBinary {
|
public final class OctalToBinary {
|
||||||
|
private OctalToBinary() {
|
||||||
|
}
|
||||||
public static long convertOctalToBinary(int octalNumber) {
|
public static long convertOctalToBinary(int octalNumber) {
|
||||||
long binaryNumber = 0;
|
long binaryNumber = 0;
|
||||||
int digitPosition = 1;
|
int digitPosition = 1;
|
||||||
|
@ -7,7 +7,9 @@ import java.util.Scanner;
|
|||||||
*
|
*
|
||||||
* @author Zachary Jones
|
* @author Zachary Jones
|
||||||
*/
|
*/
|
||||||
public class OctalToDecimal {
|
public final class OctalToDecimal {
|
||||||
|
private OctalToDecimal() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main method
|
* Main method
|
||||||
|
@ -7,7 +7,9 @@ import java.util.Scanner;
|
|||||||
*
|
*
|
||||||
* @author Tanmay Joshi
|
* @author Tanmay Joshi
|
||||||
*/
|
*/
|
||||||
public class OctalToHexadecimal {
|
public final class OctalToHexadecimal {
|
||||||
|
private OctalToHexadecimal() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method converts a Octal number to a decimal number
|
* This method converts a Octal number to a decimal number
|
||||||
|
@ -13,7 +13,9 @@ import java.util.Arrays;
|
|||||||
* (description adapted from <a href="https://en.wikipedia.org/wiki/RGB_color_model">[1]</a> and
|
* (description adapted from <a href="https://en.wikipedia.org/wiki/RGB_color_model">[1]</a> and
|
||||||
* <a href="https://en.wikipedia.org/wiki/HSL_and_HSV">[2]</a>).
|
* <a href="https://en.wikipedia.org/wiki/HSL_and_HSV">[2]</a>).
|
||||||
*/
|
*/
|
||||||
public class RgbHsvConversion {
|
public final class RgbHsvConversion {
|
||||||
|
private RgbHsvConversion() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Expected RGB-values taken from https://www.rapidtables.com/convert/color/hsv-to-rgb.html
|
// Expected RGB-values taken from https://www.rapidtables.com/convert/color/hsv-to-rgb.html
|
||||||
|
@ -3,7 +3,9 @@ package com.thealgorithms.conversions;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class RomanToInteger {
|
public final class RomanToInteger {
|
||||||
|
private RomanToInteger() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final Map<Character, Integer> ROMAN_TO_INT = new HashMap<>() {
|
private static final Map<Character, Integer> ROMAN_TO_INT = new HashMap<>() {
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,9 @@ import java.util.Scanner;
|
|||||||
*
|
*
|
||||||
* @author Özgün Gökşenli
|
* @author Özgün Gökşenli
|
||||||
*/
|
*/
|
||||||
public class TurkishToLatinConversion {
|
public final class TurkishToLatinConversion {
|
||||||
|
private TurkishToLatinConversion() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main method
|
* Main method
|
||||||
|
@ -9,7 +9,9 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.PriorityQueue;
|
import java.util.PriorityQueue;
|
||||||
|
|
||||||
public class A_Star {
|
public final class A_Star {
|
||||||
|
private A_Star() {
|
||||||
|
}
|
||||||
|
|
||||||
private static class Graph {
|
private static class Graph {
|
||||||
|
|
||||||
|
@ -14,7 +14,9 @@ import java.util.Arrays;
|
|||||||
*
|
*
|
||||||
* Output : YES
|
* Output : YES
|
||||||
*/
|
*/
|
||||||
public class BipartiteGrapfDFS {
|
public final class BipartiteGrapfDFS {
|
||||||
|
private BipartiteGrapfDFS() {
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean bipartite(int V, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
|
private static boolean bipartite(int V, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
|
||||||
if (color[node] == -1) {
|
if (color[node] == -1) {
|
||||||
|
@ -107,7 +107,9 @@ class Graph<E extends Comparable<E>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConnectedComponent {
|
public final class ConnectedComponent {
|
||||||
|
private ConnectedComponent() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Graph<Character> graphChars = new Graph<>();
|
Graph<Character> graphChars = new Graph<>();
|
||||||
|
@ -78,7 +78,9 @@ class Cycle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Cycles {
|
public final class Cycles {
|
||||||
|
private Cycles() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Cycle c = new Cycle();
|
Cycle c = new Cycle();
|
||||||
|
@ -120,7 +120,9 @@ class AdjacencyListGraph<E extends Comparable<E>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Graphs {
|
public final class Graphs {
|
||||||
|
private Graphs() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
AdjacencyListGraph<Integer> graph = new AdjacencyListGraph<>();
|
AdjacencyListGraph<Integer> graph = new AdjacencyListGraph<>();
|
||||||
|
@ -130,7 +130,9 @@ class TopologicalSort<E extends Comparable<E>> {
|
|||||||
/**
|
/**
|
||||||
* A driver class that sorts a given graph in topological order.
|
* A driver class that sorts a given graph in topological order.
|
||||||
*/
|
*/
|
||||||
public class KahnsAlgorithm {
|
public final class KahnsAlgorithm {
|
||||||
|
private KahnsAlgorithm() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Graph definition and initialization
|
// Graph definition and initialization
|
||||||
|
@ -12,7 +12,9 @@ import java.util.Queue;
|
|||||||
*
|
*
|
||||||
* @author Unknown
|
* @author Unknown
|
||||||
*/
|
*/
|
||||||
public class MatrixGraphs {
|
public final class MatrixGraphs {
|
||||||
|
private MatrixGraphs() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(10);
|
AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(10);
|
||||||
|
@ -2,7 +2,9 @@ package com.thealgorithms.datastructures.hashmap.hashing;
|
|||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public final class Main {
|
||||||
|
private Main() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int choice, key;
|
int choice, key;
|
||||||
|
@ -2,7 +2,9 @@ package com.thealgorithms.datastructures.hashmap.hashing;
|
|||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class MainCuckooHashing {
|
public final class MainCuckooHashing {
|
||||||
|
private MainCuckooHashing() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int choice, key;
|
int choice, key;
|
||||||
|
@ -8,7 +8,9 @@ This class finds the majority element(s) in an array of integers.
|
|||||||
A majority element is an element that appears more than or equal to n/2 times, where n is the length
|
A majority element is an element that appears more than or equal to n/2 times, where n is the length
|
||||||
of the array.
|
of the array.
|
||||||
*/
|
*/
|
||||||
public class MajorityElement {
|
public final class MajorityElement {
|
||||||
|
private MajorityElement() {
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
This method returns the majority element(s) in the given array of integers.
|
This method returns the majority element(s) in the given array of integers.
|
||||||
@param nums: an array of integers
|
@param nums: an array of integers
|
||||||
|
@ -2,7 +2,9 @@ package com.thealgorithms.datastructures.lists;
|
|||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class CreateAndDetectLoop {
|
public final class CreateAndDetectLoop {
|
||||||
|
private CreateAndDetectLoop() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints the linked list.
|
* Prints the linked list.
|
||||||
|
@ -6,7 +6,9 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author https://github.com/shellhub
|
* @author https://github.com/shellhub
|
||||||
*/
|
*/
|
||||||
public class MergeSortedArrayList {
|
public final class MergeSortedArrayList {
|
||||||
|
private MergeSortedArrayList() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
List<Integer> listA = new ArrayList<>();
|
List<Integer> listA = new ArrayList<>();
|
||||||
|
@ -152,7 +152,9 @@ class Queue {
|
|||||||
*
|
*
|
||||||
* @author Unknown
|
* @author Unknown
|
||||||
*/
|
*/
|
||||||
public class Queues {
|
public final class Queues {
|
||||||
|
private Queues() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main method
|
* Main method
|
||||||
|
@ -8,7 +8,9 @@ import java.util.Stack;
|
|||||||
*
|
*
|
||||||
* @author Ishika Agarwal, 2021
|
* @author Ishika Agarwal, 2021
|
||||||
*/
|
*/
|
||||||
public class ReverseStack {
|
public final class ReverseStack {
|
||||||
|
private ReverseStack() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try (Scanner sc = new Scanner(System.in)) {
|
try (Scanner sc = new Scanner(System.in)) {
|
||||||
|
@ -6,7 +6,9 @@ import java.util.NoSuchElementException;
|
|||||||
* @author Varun Upadhyay (https://github.com/varunu28)
|
* @author Varun Upadhyay (https://github.com/varunu28)
|
||||||
*/
|
*/
|
||||||
// An implementation of a Stack using a Linked List
|
// An implementation of a Stack using a Linked List
|
||||||
class StackOfLinkedList {
|
final class StackOfLinkedList {
|
||||||
|
private StackOfLinkedList() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
LinkedListStack stack = new LinkedListStack();
|
LinkedListStack stack = new LinkedListStack();
|
||||||
|
@ -9,7 +9,9 @@ import com.thealgorithms.datastructures.trees.BinaryTree.Node;
|
|||||||
* left half recursively to create left subtree 3. Use the right half
|
* left half recursively to create left subtree 3. Use the right half
|
||||||
* recursively to create right subtree
|
* recursively to create right subtree
|
||||||
*/
|
*/
|
||||||
public class BSTFromSortedArray {
|
public final class BSTFromSortedArray {
|
||||||
|
private BSTFromSortedArray() {
|
||||||
|
}
|
||||||
public static Node createBST(int[] array) {
|
public static Node createBST(int[] array) {
|
||||||
if (array == null || array.length == 0) {
|
if (array == null || array.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -42,7 +42,9 @@ import com.thealgorithms.datastructures.trees.BinaryTree.Node;
|
|||||||
* subtree. If left subtree returns a non-null value then that will be ceil
|
* subtree. If left subtree returns a non-null value then that will be ceil
|
||||||
* otherwise the root is ceil
|
* otherwise the root is ceil
|
||||||
*/
|
*/
|
||||||
public class CeilInBinarySearchTree {
|
public final class CeilInBinarySearchTree {
|
||||||
|
private CeilInBinarySearchTree() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Node getCeil(Node root, int key) {
|
public static Node getCeil(Node root, int key) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
|
@ -8,7 +8,9 @@ package com.thealgorithms.datastructures.trees;
|
|||||||
* where 'min' and 'max' values represent the child nodes (left, right).
|
* where 'min' and 'max' values represent the child nodes (left, right).
|
||||||
* 2. The smallest possible node value is Integer.MIN_VALUE, the biggest - Integer.MAX_VALUE.
|
* 2. The smallest possible node value is Integer.MIN_VALUE, the biggest - Integer.MAX_VALUE.
|
||||||
*/
|
*/
|
||||||
public class CheckBinaryTreeIsValidBST {
|
public final class CheckBinaryTreeIsValidBST {
|
||||||
|
private CheckBinaryTreeIsValidBST() {
|
||||||
|
}
|
||||||
public static boolean isBST(BinaryTree.Node root) {
|
public static boolean isBST(BinaryTree.Node root) {
|
||||||
return isBSTUtil(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
return isBSTUtil(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ import java.util.Stack;
|
|||||||
*
|
*
|
||||||
* @author [Ian Cowan](<a href="https://github.com/iccowan">Git-Ian Cowan</a>)
|
* @author [Ian Cowan](<a href="https://github.com/iccowan">Git-Ian Cowan</a>)
|
||||||
*/
|
*/
|
||||||
public class CheckIfBinaryTreeBalanced {
|
public final class CheckIfBinaryTreeBalanced {
|
||||||
|
private CheckIfBinaryTreeBalanced() {
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Recursive is BT balanced implementation
|
* Recursive is BT balanced implementation
|
||||||
*
|
*
|
||||||
|
@ -30,7 +30,9 @@ import com.thealgorithms.datastructures.trees.BinaryTree.Node;
|
|||||||
*
|
*
|
||||||
* @author kumanoit on 10/10/22 IST 12:52 AM
|
* @author kumanoit on 10/10/22 IST 12:52 AM
|
||||||
*/
|
*/
|
||||||
public class CheckTreeIsSymmetric {
|
public final class CheckTreeIsSymmetric {
|
||||||
|
private CheckTreeIsSymmetric() {
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isSymmetric(Node root) {
|
public static boolean isSymmetric(Node root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
|
@ -17,7 +17,9 @@ import java.util.Map;
|
|||||||
* Complexity: Time: O(n) hashmap reduced iteration to find index in inorder
|
* Complexity: Time: O(n) hashmap reduced iteration to find index in inorder
|
||||||
* array Space: O(n) space taken by hashmap
|
* array Space: O(n) space taken by hashmap
|
||||||
*/
|
*/
|
||||||
public class CreateBinaryTreeFromInorderPreorder {
|
public final class CreateBinaryTreeFromInorderPreorder {
|
||||||
|
private CreateBinaryTreeFromInorderPreorder() {
|
||||||
|
}
|
||||||
public static Node createTree(final Integer[] preorder, final Integer[] inorder) {
|
public static Node createTree(final Integer[] preorder, final Integer[] inorder) {
|
||||||
if (preorder == null || inorder == null) {
|
if (preorder == null || inorder == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -25,7 +25,9 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Albina Gimaletdinova on 21/02/2023
|
* @author Albina Gimaletdinova on 21/02/2023
|
||||||
*/
|
*/
|
||||||
public class InorderTraversal {
|
public final class InorderTraversal {
|
||||||
|
private InorderTraversal() {
|
||||||
|
}
|
||||||
public static List<Integer> recursiveInorder(BinaryTree.Node root) {
|
public static List<Integer> recursiveInorder(BinaryTree.Node root) {
|
||||||
List<Integer> result = new ArrayList<>();
|
List<Integer> result = new ArrayList<>();
|
||||||
recursiveInorder(root, result);
|
recursiveInorder(root, result);
|
||||||
|
@ -3,7 +3,9 @@ package com.thealgorithms.datastructures.trees;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class LCA {
|
public final class LCA {
|
||||||
|
private LCA() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final Scanner SCANNER = new Scanner(System.in);
|
private static final Scanner SCANNER = new Scanner(System.in);
|
||||||
|
|
||||||
|
@ -5,7 +5,9 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
public class LevelOrderTraversal {
|
public final class LevelOrderTraversal {
|
||||||
|
private LevelOrderTraversal() {
|
||||||
|
}
|
||||||
|
|
||||||
public static List<List<Integer>> traverse(BinaryTree.Node root) {
|
public static List<List<Integer>> traverse(BinaryTree.Node root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
|
@ -26,7 +26,9 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Albina Gimaletdinova on 21/02/2023
|
* @author Albina Gimaletdinova on 21/02/2023
|
||||||
*/
|
*/
|
||||||
public class PostOrderTraversal {
|
public final class PostOrderTraversal {
|
||||||
|
private PostOrderTraversal() {
|
||||||
|
}
|
||||||
public static List<Integer> recursivePostOrder(BinaryTree.Node root) {
|
public static List<Integer> recursivePostOrder(BinaryTree.Node root) {
|
||||||
List<Integer> result = new ArrayList<>();
|
List<Integer> result = new ArrayList<>();
|
||||||
recursivePostOrder(root, result);
|
recursivePostOrder(root, result);
|
||||||
|
@ -25,7 +25,9 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Albina Gimaletdinova on 17/02/2023
|
* @author Albina Gimaletdinova on 17/02/2023
|
||||||
*/
|
*/
|
||||||
public class PreOrderTraversal {
|
public final class PreOrderTraversal {
|
||||||
|
private PreOrderTraversal() {
|
||||||
|
}
|
||||||
public static List<Integer> recursivePreOrder(BinaryTree.Node root) {
|
public static List<Integer> recursivePreOrder(BinaryTree.Node root) {
|
||||||
List<Integer> result = new ArrayList<>();
|
List<Integer> result = new ArrayList<>();
|
||||||
recursivePreOrder(root, result);
|
recursivePreOrder(root, result);
|
||||||
|
@ -87,7 +87,9 @@ class Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Driver class to test above methods
|
// Driver class to test above methods
|
||||||
public class PrintTopViewofTree {
|
public final class PrintTopViewofTree {
|
||||||
|
private PrintTopViewofTree() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
/* Create following Binary Tree
|
/* Create following Binary Tree
|
||||||
|
@ -32,7 +32,9 @@ import java.util.Deque;
|
|||||||
*
|
*
|
||||||
* @author Albina Gimaletdinova on 13/01/2023
|
* @author Albina Gimaletdinova on 13/01/2023
|
||||||
*/
|
*/
|
||||||
public class SameTreesCheck {
|
public final class SameTreesCheck {
|
||||||
|
private SameTreesCheck() {
|
||||||
|
}
|
||||||
public static boolean check(BinaryTree.Node p, BinaryTree.Node q) {
|
public static boolean check(BinaryTree.Node p, BinaryTree.Node q) {
|
||||||
if (p == null && q == null) {
|
if (p == null && q == null) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -20,7 +20,9 @@ in a tree from top to bottom and left to right, so for a tree :
|
|||||||
the sequence will be :
|
the sequence will be :
|
||||||
4 2 7 1 5 9 3 8 6 10
|
4 2 7 1 5 9 3 8 6 10
|
||||||
*/
|
*/
|
||||||
public class VerticalOrderTraversal {
|
public final class VerticalOrderTraversal {
|
||||||
|
private VerticalOrderTraversal() {
|
||||||
|
}
|
||||||
|
|
||||||
/*Function that receives a root Node and prints the tree
|
/*Function that receives a root Node and prints the tree
|
||||||
in Vertical Order.*/
|
in Vertical Order.*/
|
||||||
|
@ -34,7 +34,9 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Albina Gimaletdinova on 11/01/2023
|
* @author Albina Gimaletdinova on 11/01/2023
|
||||||
*/
|
*/
|
||||||
public class ZigzagTraversal {
|
public final class ZigzagTraversal {
|
||||||
|
private ZigzagTraversal() {
|
||||||
|
}
|
||||||
public static List<List<Integer>> traverse(BinaryTree.Node root) {
|
public static List<List<Integer>> traverse(BinaryTree.Node root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
return List.of();
|
return List.of();
|
||||||
|
@ -3,7 +3,9 @@ package com.thealgorithms.datastructures.trees;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
class Main {
|
final class NearestRightKey {
|
||||||
|
private NearestRightKey() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
NRKTree root = BuildTree();
|
NRKTree root = BuildTree();
|
||||||
|
@ -25,7 +25,9 @@ int n=10;
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class BoardPath {
|
public final class BoardPath {
|
||||||
|
private BoardPath() {
|
||||||
|
}
|
||||||
|
|
||||||
public static long startTime;
|
public static long startTime;
|
||||||
public static long endTime;
|
public static long endTime;
|
||||||
|
@ -4,7 +4,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
* Java program for Boundary fill algorithm.
|
* Java program for Boundary fill algorithm.
|
||||||
* @author Akshay Dubey (https://github.com/itsAkshayDubey)
|
* @author Akshay Dubey (https://github.com/itsAkshayDubey)
|
||||||
*/
|
*/
|
||||||
public class BoundaryFill {
|
public final class BoundaryFill {
|
||||||
|
private BoundaryFill() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the color at the given co-odrinates of a 2D image
|
* Get the color at the given co-odrinates of a 2D image
|
||||||
|
@ -2,7 +2,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
|
|
||||||
/* A Naive recursive implementation
|
/* A Naive recursive implementation
|
||||||
of 0-1 Knapsack problem */
|
of 0-1 Knapsack problem */
|
||||||
public class BruteForceKnapsack {
|
public final class BruteForceKnapsack {
|
||||||
|
private BruteForceKnapsack() {
|
||||||
|
}
|
||||||
// Returns the maximum value that
|
// Returns the maximum value that
|
||||||
// can be put in a knapsack of
|
// can be put in a knapsack of
|
||||||
// capacity W
|
// capacity W
|
||||||
|
@ -10,7 +10,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
*/
|
*/
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class CatalanNumber {
|
public final class CatalanNumber {
|
||||||
|
private CatalanNumber() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method finds the nth Catalan number
|
* This method finds the nth Catalan number
|
||||||
|
@ -5,7 +5,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
|
|
||||||
Link : https://medium.com/analytics-vidhya/leetcode-q70-climbing-stairs-easy-444a4aae54e8
|
Link : https://medium.com/analytics-vidhya/leetcode-q70-climbing-stairs-easy-444a4aae54e8
|
||||||
*/
|
*/
|
||||||
public class ClimbingStairs {
|
public final class ClimbingStairs {
|
||||||
|
private ClimbingStairs() {
|
||||||
|
}
|
||||||
|
|
||||||
public static int numberOfWays(int n) {
|
public static int numberOfWays(int n) {
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
/**
|
/**
|
||||||
* @author Varun Upadhyay (https://github.com/varunu28)
|
* @author Varun Upadhyay (https://github.com/varunu28)
|
||||||
*/
|
*/
|
||||||
public class CoinChange {
|
public final class CoinChange {
|
||||||
|
private CoinChange() {
|
||||||
|
}
|
||||||
|
|
||||||
// Driver Program
|
// Driver Program
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
|
|
||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
public class CountFriendsPairing {
|
public final class CountFriendsPairing {
|
||||||
|
private CountFriendsPairing() {
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean countFriendsPairing(int n, int[] a) {
|
public static boolean countFriendsPairing(int n, int[] a) {
|
||||||
int[] dp = new int[n + 1];
|
int[] dp = new int[n + 1];
|
||||||
|
@ -13,7 +13,9 @@ Following is implementation of Dynamic Programming approach. */
|
|||||||
// Code ---->
|
// Code ---->
|
||||||
// Java program to find number of ways to get sum 'x' with 'n'
|
// Java program to find number of ways to get sum 'x' with 'n'
|
||||||
// dice where every dice has 'm' faces
|
// dice where every dice has 'm' faces
|
||||||
class DP {
|
final class DP {
|
||||||
|
private DP() {
|
||||||
|
}
|
||||||
|
|
||||||
/* The main function that returns the number of ways to get sum 'x' with 'n' dice and 'm' with m
|
/* The main function that returns the number of ways to get sum 'x' with 'n' dice and 'm' with m
|
||||||
* faces. */
|
* faces. */
|
||||||
|
@ -24,7 +24,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
*/
|
*/
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class EditDistance {
|
public final class EditDistance {
|
||||||
|
private EditDistance() {
|
||||||
|
}
|
||||||
|
|
||||||
public static int minDistance(String word1, String word2) {
|
public static int minDistance(String word1, String word2) {
|
||||||
int len1 = word1.length();
|
int len1 = word1.length();
|
||||||
|
@ -3,7 +3,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
/**
|
/**
|
||||||
* DynamicProgramming solution for the Egg Dropping Puzzle
|
* DynamicProgramming solution for the Egg Dropping Puzzle
|
||||||
*/
|
*/
|
||||||
public class EggDropping {
|
public final class EggDropping {
|
||||||
|
private EggDropping() {
|
||||||
|
}
|
||||||
|
|
||||||
// min trials with n eggs and m floors
|
// min trials with n eggs and m floors
|
||||||
public static int minTrials(int n, int m) {
|
public static int minTrials(int n, int m) {
|
||||||
|
@ -7,7 +7,9 @@ import java.util.Scanner;
|
|||||||
/**
|
/**
|
||||||
* @author Varun Upadhyay (https://github.com/varunu28)
|
* @author Varun Upadhyay (https://github.com/varunu28)
|
||||||
*/
|
*/
|
||||||
public class Fibonacci {
|
public final class Fibonacci {
|
||||||
|
private Fibonacci() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final Map<Integer, Integer> CACHE = new HashMap<>();
|
private static final Map<Integer, Integer> CACHE = new HashMap<>();
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@ import java.util.LinkedList;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
public class FordFulkerson {
|
public final class FordFulkerson {
|
||||||
|
private FordFulkerson() {
|
||||||
|
}
|
||||||
|
|
||||||
static final int INF = 987654321;
|
static final int INF = 987654321;
|
||||||
// edges
|
// edges
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
/** Program description - To find the maximum subarray sum */
|
/** Program description - To find the maximum subarray sum */
|
||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
public class KadaneAlgorithm {
|
public final class KadaneAlgorithm {
|
||||||
|
private KadaneAlgorithm() {
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean max_Sum(int[] a, int predicted_answer) {
|
public static boolean max_Sum(int[] a, int predicted_answer) {
|
||||||
int sum = a[0], running_sum = 0;
|
int sum = a[0], running_sum = 0;
|
||||||
|
@ -11,7 +11,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
x1 < x2 > x3 < x4 > x5 < …. xn or
|
x1 < x2 > x3 < x4 > x5 < …. xn or
|
||||||
x1 > x2 < x3 > x4 < x5 > …. xn
|
x1 > x2 < x3 > x4 < x5 > …. xn
|
||||||
*/
|
*/
|
||||||
public class LongestAlternatingSubsequence {
|
public final class LongestAlternatingSubsequence {
|
||||||
|
private LongestAlternatingSubsequence() {
|
||||||
|
}
|
||||||
|
|
||||||
/* Function to return longest alternating subsequence length*/
|
/* Function to return longest alternating subsequence length*/
|
||||||
static int AlternatingLength(int[] arr, int n) {
|
static int AlternatingLength(int[] arr, int n) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
class LongestCommonSubsequence {
|
final class LongestCommonSubsequence {
|
||||||
|
private LongestCommonSubsequence() {
|
||||||
|
}
|
||||||
|
|
||||||
public static String getLCS(String str1, String str2) {
|
public static String getLCS(String str1, String str2) {
|
||||||
// At least one string is null
|
// At least one string is null
|
||||||
|
@ -5,7 +5,9 @@ import java.util.Scanner;
|
|||||||
/**
|
/**
|
||||||
* @author Afrizal Fikri (https://github.com/icalF)
|
* @author Afrizal Fikri (https://github.com/icalF)
|
||||||
*/
|
*/
|
||||||
public class LongestIncreasingSubsequence {
|
public final class LongestIncreasingSubsequence {
|
||||||
|
private LongestIncreasingSubsequence() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
|
@ -4,7 +4,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
* Algorithm explanation
|
* Algorithm explanation
|
||||||
* https://www.educative.io/edpresso/longest-palindromic-subsequence-algorithm
|
* https://www.educative.io/edpresso/longest-palindromic-subsequence-algorithm
|
||||||
*/
|
*/
|
||||||
public class LongestPalindromicSubsequence {
|
public final class LongestPalindromicSubsequence {
|
||||||
|
private LongestPalindromicSubsequence() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String a = "BBABCBCAB";
|
String a = "BBABCBCAB";
|
||||||
|
@ -3,7 +3,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
/*
|
/*
|
||||||
* Algorithm explanation https://leetcode.com/problems/longest-palindromic-substring/
|
* Algorithm explanation https://leetcode.com/problems/longest-palindromic-substring/
|
||||||
*/
|
*/
|
||||||
public class LongestPalindromicSubstring {
|
public final class LongestPalindromicSubstring {
|
||||||
|
private LongestPalindromicSubstring() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String a = "babad";
|
String a = "babad";
|
||||||
|
@ -7,7 +7,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
* @author Libin Yang (https://github.com/yanglbme)
|
* @author Libin Yang (https://github.com/yanglbme)
|
||||||
* @since 2018/10/5
|
* @since 2018/10/5
|
||||||
*/
|
*/
|
||||||
public class LongestValidParentheses {
|
public final class LongestValidParentheses {
|
||||||
|
private LongestValidParentheses() {
|
||||||
|
}
|
||||||
|
|
||||||
public static int getLongestValidParentheses(String s) {
|
public static int getLongestValidParentheses(String s) {
|
||||||
if (s == null || s.length() < 2) {
|
if (s == null || s.length() < 2) {
|
||||||
|
@ -4,7 +4,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class MatrixChainMultiplication {
|
public final class MatrixChainMultiplication {
|
||||||
|
private MatrixChainMultiplication() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final Scanner SCANNER = new Scanner(System.in);
|
private static final Scanner SCANNER = new Scanner(System.in);
|
||||||
private static final ArrayList<Matrix> MATRICES = new ArrayList<>();
|
private static final ArrayList<Matrix> MATRICES = new ArrayList<>();
|
||||||
|
@ -6,7 +6,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
// matrix Ai has dimension pi−1 ×pi
|
// matrix Ai has dimension pi−1 ×pi
|
||||||
// , fully parenthesize the product A1A2 ···An in a way that
|
// , fully parenthesize the product A1A2 ···An in a way that
|
||||||
// minimizes the number of scalar multiplications.
|
// minimizes the number of scalar multiplications.
|
||||||
public class MatrixChainRecursiveTopDownMemoisation {
|
public final class MatrixChainRecursiveTopDownMemoisation {
|
||||||
|
private MatrixChainRecursiveTopDownMemoisation() {
|
||||||
|
}
|
||||||
|
|
||||||
static int Memoized_Matrix_Chain(int[] p) {
|
static int Memoized_Matrix_Chain(int[] p) {
|
||||||
int n = p.length;
|
int n = p.length;
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
|
|
||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
public class NewManShanksPrime {
|
public final class NewManShanksPrime {
|
||||||
|
private NewManShanksPrime() {
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean nthManShanksPrime(int n, int expected_answer) {
|
public static boolean nthManShanksPrime(int n, int expected_answer) {
|
||||||
int[] a = new int[n + 1];
|
int[] a = new int[n + 1];
|
||||||
|
@ -17,7 +17,9 @@ import java.util.Scanner;
|
|||||||
* "aba | b | bbabb | ababa"
|
* "aba | b | bbabb | ababa"
|
||||||
* @author [Syed] (https://github.com/roeticvampire)
|
* @author [Syed] (https://github.com/roeticvampire)
|
||||||
*/
|
*/
|
||||||
public class PalindromicPartitioning {
|
public final class PalindromicPartitioning {
|
||||||
|
private PalindromicPartitioning() {
|
||||||
|
}
|
||||||
|
|
||||||
public static int minimalpartitions(String word) {
|
public static int minimalpartitions(String word) {
|
||||||
int len = word.length();
|
int len = word.length();
|
||||||
|
@ -18,7 +18,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class PartitionProblem {
|
public final class PartitionProblem {
|
||||||
|
private PartitionProblem() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if a set of integers can be partitioned into two subsets such that the sum of elements
|
* Test if a set of integers can be partitioned into two subsets such that the sum of elements
|
||||||
|
@ -12,7 +12,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
* length of pat
|
* length of pat
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RegexMatching {
|
public final class RegexMatching {
|
||||||
|
private RegexMatching() {
|
||||||
|
}
|
||||||
|
|
||||||
// Method 1: Using Recursion
|
// Method 1: Using Recursion
|
||||||
// Time Complexity=0(2^(N+M)) Space Complexity=Recursion Extra Space
|
// Time Complexity=0(2^(N+M)) Space Complexity=Recursion Extra Space
|
||||||
|
@ -4,7 +4,9 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
* A Dynamic Programming solution for the Rod cutting problem.
|
* A Dynamic Programming solution for the Rod cutting problem.
|
||||||
* Returns the best obtainable price for a rod of length n and price[] as prices of different pieces.
|
* Returns the best obtainable price for a rod of length n and price[] as prices of different pieces.
|
||||||
*/
|
*/
|
||||||
public class RodCutting {
|
public final class RodCutting {
|
||||||
|
private RodCutting() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method calculates the maximum obtainable value for cutting a rod of length n
|
* This method calculates the maximum obtainable value for cutting a rod of length n
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
// Java program to find length of the shortest supersequence
|
// Java program to find length of the shortest supersequence
|
||||||
class ShortestSuperSequence {
|
final class ShortestSuperSequence {
|
||||||
|
private ShortestSuperSequence() {
|
||||||
|
}
|
||||||
|
|
||||||
// Function to find length of the
|
// Function to find length of the
|
||||||
// shortest supersequence of X and Y.
|
// shortest supersequence of X and Y.
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
public class SubsetSum {
|
public final class SubsetSum {
|
||||||
|
private SubsetSum() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver Code
|
* Driver Code
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user