-
Notifications
You must be signed in to change notification settings - Fork 79
Feature #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feature #1
Conversation
| @Override | ||
| public List<String> getWords(String text) { | ||
| return new ArrayList<>(); | ||
| return new ArrayList<>(Arrays.asList(text.split("\\W+"))); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У тебя же это будет вызываться для каждой копии слова в листе слов?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, получается решение более медленное с точки зрения времени выполнения, но более быстрое для программиста :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Наверное, надо было использовать список уникальных слов, а частоту их употребления собирать из списка всех слов.
No description provided.