Answer the question
In order to leave comments, you need to log in
How to solve a problem without arrays?
The essence of the problem: there is a string, you need to find the number of characters that are most common and output in this type
if the original string is hhyhddrdffrfaasxf
h-3
d-3
f-3
With arrays, the problem is very simple. How to solve this problem without using arrays and collections.
Answer the question
In order to leave comments, you need to log in
Well, in php it is possible through str_replace by using the last parameter count (count of replacements made), in java there is an analogue or not, I don’t know ...
Well, since hashes and tables can't be used, you're probably left with just graph data structures.
just on the forehead?
class G_tost {
public static int getCount(String s, char ch) {
int res = 0;
for (int i = 0; i < s.length(); i++) {
res += s.charAt(i) == ch ? 1 : 0;
}
return res;
}
public static void main(String[] args) {
String data = "hhyhddrdffrfaasxf";
int ans = 0;
char ch = data.charAt(0);
for (int i = 0; i < data.length(); i++) {
int l = getCount(data, data.charAt(i));
if (ans < l) {
ch = data.charAt(i);
ans = l;
}
}
System.out.format("Char: %c, count: %d\n", ch, ans);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question