-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputeDepth_fromgithub.java
More file actions
153 lines (100 loc) · 2.79 KB
/
Copy pathcomputeDepth_fromgithub.java
File metadata and controls
153 lines (100 loc) · 2.79 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
150
151
152
153
class computeDepth_fromgithub {
public static void main(String[] args) {
System.out.println(computeDepth(13));
}
/**
* [computeDepth description]
* @param n [description]
* @return integer 1 if true otherwise 0 [description]
*/
public static int computeDepth(int n) {
int i = 1;
int j = 0;
int k = 0;
boolean hasContribute = false;
boolean search = true;
int[] contribute = new int[10];
for (int a = 0; a < contribute.length; a++) {
contribute[a] = -1;
}
int count = 0;
int digits = 0;
while (search) {
j = n * i;
while (j > 0) {
k = j % 10;
j = j / 10;
hasContribute = false;
for (int l = 0; l < contribute.length; l++) {
if (contribute[l] == k) {
hasContribute = true;
l = contribute.length;
}
}
if (!hasContribute) {
contribute[count] = k;
count++;
}
digits = 0;
for (int m = 0; m <= 9; m++) {
for (int x = 0; x < contribute.length; x++) {
if (m == contribute[x]) {
digits++;
x = contribute.length;
}
}
}
}
if (digits == 10) {
search = false;
return i;
}
i++;
}
return 0;
}
/**
* [matches description]
* @param a [description]
* @param p [description]
* @return integer 1 if true otherwise 0 [description]
*/
public static int matches(int[ ] a, int[ ] p) {
int start = 0;
int end = 0;
int len = 0;
for (int i = 0; i < p.length; i++) {
if (p[i] < 0)
len = p[i] * ( -1 );
else
len = p[i];
end += len;
for (int j = start; j < end; j++) {
if (p[i] > 0) {
if (a[j] < 0) return 0;
} else {
if (a[j] > 0) return 0;
}
}
start += len;
}
return 1;
}
/**
* [isStacked description]
* @param n [description]
* @return integer 1 if true otherwise 0 [description]
*/
public static int isStacked(int n) {
int i = 1;
int sum = 0;
while (i <= n) {
sum += i;
if (sum == n) {
return 1;
}
i++;
}
return 0;
}
}