Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion DataStructures/Stacks/BalancedBrackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class BalancedBrackets {
* @return
*/
static boolean is_balanced(String s) {
if (s == null || s.length() % 2 != 0) {
return false;
}
Stack<Character> bracketsStack = new Stack<>();
char[] text = s.toCharArray();
for (char x : text) {
Expand Down Expand Up @@ -82,8 +85,9 @@ public static void main(String args[]) {
if (is_balanced(s)) {
System.out.println(s + " is balanced");
} else {
System.out.println(s + " ain't balanced");
System.out.println(s + " isn't balanced");
}
in.close();
}
}
}
4 changes: 4 additions & 0 deletions DynamicProgramming/CoinChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static void main(String[] args) {
**/
public static int change(int[] coins, int amount) {

if(amount<0&& coins==null||coins.length==0)
{
return 0;
}
int[] combinations = new int[amount + 1];
combinations[0] = 1;

Expand Down
9 changes: 7 additions & 2 deletions Searches/SaddlebackSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ else if (arr[row][col] > key) {
*
* @param args Command line arguments
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int arr[][];
int i, j, rows = sc.nextInt(), col = sc.nextInt();
if(rows<=0 || col<=0)
{
System.out.println("Invalid Input");
return;
}
arr = new int[rows][col];
for (i = 0; i < rows; i++) {
for (j = 0; j < col; j++) {
Expand Down