-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolutions.java
More file actions
149 lines (125 loc) · 2.58 KB
/
Solutions.java
File metadata and controls
149 lines (125 loc) · 2.58 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
class Solution {
public int solution(int N) {
// write your code in Java SE 8
int maxGap = 0;
String bin = Integer.toBinaryString(N);
bin.chars()
.mapToObj(i -> (char) i)
.forEach(i -> {
if(i == '1') {
System.out.println(i);
}
});
return maxGap;
}
public static void main(String[] args) {
int A = 3;
int B = 3;
// write your code in Java SE 8
String a = "a";
String b = "b";
String returnText = "";
int maxConsecutiveA = 0;
int maxConsecutiveB = 0;
if(A>B) {
while(A>0) {
if(maxConsecutiveA < 2) {
returnText = returnText + a;
maxConsecutiveA ++;
A--;
continue;
} else {
maxConsecutiveA = 0;
}
while(B>0) {
if(maxConsecutiveB < 2) {
returnText = returnText + b;
maxConsecutiveB ++;
B--;
continue;
} else {
maxConsecutiveB = 0;
break;
}
}
}
} else {
while(B>0) {
if(maxConsecutiveB < 2) {
returnText = returnText + b;
maxConsecutiveB ++;
B--;
continue;
} else {
maxConsecutiveB = 0;
}
while(A>0) {
if(maxConsecutiveA < 2) {
returnText = returnText + a;
maxConsecutiveA ++;
A--;
continue;
} else {
maxConsecutiveA = 0;
break;
}
}
}
}
System.out.println("returnText: " + returnText);
}
}
class Solution2 {
public static void main(String[] args) {
int A = 3;
int B = 3;
int sum= A + B;
int fark = A - B;
String s="";
if ( fark > 0 ) {
int ikiliCount = fark;
for ( int i=0;i<ikiliCount;i++) {
s = s + "aa" + "b";
}
for (int i=s.length();s.length()<sum;i++) {
s= s + "ab";
}
} else {
int ikiliCount = fark * -1;
//System.out.println("sonuc" + ikiliCount);
for ( int i=0;i<ikiliCount;i++) {
s = s + "bb" + "a";
}
for (int i=s.length();s.length()<sum;i++) {
s = s + "ba";
}
}
s= s.substring(0,sum);
//System.out.println(s);
System.out.println("returnText: " + s);
}
}
class Solution3 {
public static void main(String[] args) {
String S = "";
// write your code in Java SE 8
int returnValue = 0;
if(S.length()%2==0) {
returnValue = -1;
} else {
int midpoint = new Double(Math.floor(S.length()/2)).intValue();
String left = S.substring(0, midpoint);
String right = S.substring(midpoint +1);
right = reverse(right);
if (left.equals(right)) {
returnValue = midpoint;
} else {
returnValue= -1;
}
}
System.out.println(returnValue);
}
public static String reverse(String str) {
return new StringBuilder(str).reverse().toString();
}
}