Как преобразовать этот код C++ в java
// C++ Program to find the size of // largest subset of anagram #include <bits/stdc++.h> using namespace std; // Utility function to find size of // largest subset of anagram int largestAnagramSet(string arr[], int n) { int maxSize = 0; // Initialize map<> of vector array map<vector<int>, int> count; for (int i = 0; i < n; ++i) { // Vector array to store // frequency of element vector<int> freq(26); for (char ch : arr[i]) freq[ch - 'a'] += 1; // Increment the count of // frequency array in map<> count[freq] += 1; // Compute the maximum size maxSize = max(maxSize, count[freq]); } return maxSize; } // Driver code int main() { string arr[] = { "ant", "magenta", "magnate", "tan", "gnamate" }; int n = sizeof(arr) / sizeof(arr[0]); cout << largestAnagramSet(arr, n) << "\n"; string arr1[] = { "cars", "bikes", "arcs", "steer" }; n = sizeof(arr1) / sizeof(arr[0]); cout << largestAnagramSet(arr1, n); return 0; }
Что я уже пробовал:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package hw1; import java.util.ArrayList; import java.util.Arrays; /** * * @author rafeaaalbloushi */ public class anagram { public int largestAnagramSet(String arr[], int n) { int maxSize = 0; ArrayList<String, int>=new ArrayList; for (int i = 0; i < n; ++i) { // sort the string Arrays.sort(a, maxSize, i); // Increment the count of string count[arr[i]] += 1; // Compute the maximum size of string maxSize = max(maxSize, count[arr[i]]); } return maxSize; } }
OriginalGriff
И что же?
Что он делает такого, чего вы не ожидали, или не делает того, что вы сделали?
ZurdoDev
Где ты застрял?
rafeaa27
он выдает ошибки, когда я пытаюсь запустить его на java