-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday11_2.java
More file actions
56 lines (41 loc) · 1.03 KB
/
day11_2.java
File metadata and controls
56 lines (41 loc) · 1.03 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
class Solution {
char kthCharacter(int m, int n, int k) {
// code here
StringBuilder sb = new StringBuilder();
int quo = m/2;
int re = m%2;
sb.append(String.valueOf(re));
while(quo>0)
{
int t= quo;
quo = quo/2;
re = t%2 ;
sb.append(String.valueOf(re));
}
sb.reverse();
String s = sb.toString();
String ans ="";
for(int i=1; i<=n; i++)
{
ans="";
for(int j = 0; j<s.length(); j++)
{
if(s.charAt(j)=='0')
{
ans = ans+ "01";
}
else
{
ans= ans + "10";
}
}
s = ans;
}
char c='-';
if(s.length()>=k)
{
c = s.charAt(k-1);
}
return c;
}
}