Skip to content

Conversation

@victortwin
Copy link

No description provided.

@Override
public List<String> getWords(String text) {
return new ArrayList<>();
return new ArrayList<>(Arrays.asList(text.split("\\W+")));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно просто Arrays.asList(text.split("\\W+"))

@Override
public List<String> sortWordsByLength(String text, Direction direction) {
return new ArrayList<>();
ArrayList<String> allWords = (ArrayList<String>) getWords(text);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем явно указывать ArrayList

List<String> listOfWords = new ArrayList<>();
String [] arrayOfWords = text.split("\\W+");
Arrays.stream(arrayOfWords).forEach(listOfWords::add);
return listOfWords;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream.of(text.split("\W+").collect(Collectors.toList());

Map<String, Integer> countWordsRepetitionsMap = new LinkedHashMap<>();
for (String s : allWords) {
int repetitionCounter = Collections.frequency(allWords, s);
countWordsRepetitionsMap.put(s, repetitionCounter);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя же это будет вызываться для каждой копии слова в листе слов?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, получается решение более медленное с точки зрения времени выполнения, но более быстрое для программиста :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверное, надо было использовать список уникальных слов, а частоту их употребления собирать из списка всех слов.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants