forked from JFulgoni/Java-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
128 lines (118 loc) · 2.9 KB
/
Copy pathSolution.java
File metadata and controls
128 lines (118 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package john_test;
public class Solution {
public static String[] Braces(String[] values){
String[] result = new String[values.length];
String current;
for(int i = 0; i < values.length; ++i){
current = values[i];
if(BraceCheck(current)){
result[i] = "YES";
}
else{
result[i] = "NO";
}
}
return result;
}
public static boolean BraceCheck(String current){
int paren = 0;
int square = 0;
int curly = 0;
char myChar;
for(int j = 0; j < current.length(); ++j){
myChar = current.charAt(j);
switch(myChar){
case '(':
++paren;
break;
case ')':
--paren;
break;
case '[':
++square;
break;
case ']':
--square;
break;
case '{':
++curly;
break;
case '}':
--curly;
}//end switch case
if(paren == -1 || square == -1 || curly == -1){
return false;
}
}
if(paren != 0 || square != 0 || curly != 0){
return false;
}
return true;
}
public static int getIntComplement(int n){
int copy = n;
double p = 2;
int place = 1;
while(p < copy){
p = p * 2;
++place;
}
System.out.println(place);
System.out.println(Math.pow(2, 7));
int[] bin = new int[place];
--place; // to account for it
for(int i = place; i >= 0; --i){
bin[place] = (int) (copy / Math.pow(2, i));
//I don't know why it's printing correctly here
System.out.println("In place");
System.out.println(bin[place]);
if(bin[place] == 1){
copy = (int) (copy % Math.pow(2, i));
}
}
int result = 0;
for(int j = 0; j < bin.length; j++){
//but not here
System.out.println("In Test");
System.out.println(bin[j]);
if(bin[j] == 1){
//System.out.println(Math.pow(2, bin.length - j));
result += (int) Math.pow(2, j + 1);
}
}
System.out.println("Answer:");
return result;
}
public static void findDuplicates(int[] array){
int size = array.length;
for(int i = 0; i < size; ++i){
if(array[Math.abs(array[i])] >= 0){
array[Math.abs(array[i])] = -array[Math.abs(array[i])];
}
else{
System.out.println(Math.abs(array[i]));
}
}
}
public static void main(String[] args) {
// String[] values = new String[]{"{[]}", "}[]}"};
// String[] result = Braces(values);
// for(String res : result){
// System.out.println(res);
// }
//System.out.println(getIntComplement(100));
//int[] dup = new int[]{1, 3, 4, 6, 3, 7, 6, 1};
//findDuplicates(dup);
int n = 6;
for(int i = 1; i < n + 1; ++i){
int j;
for(j = 0; j < (n - i); ++j){
System.out.print(" ");
}
for(int k = 0; k < (n - j); ++k){
System.out.print("#");
}
System.out.print("\n");
}
}
}