Logo
TGCATALOG
Catalog Collections Blog
Java | LeetCode

Java | LeetCode

LeetCode tasks and solutions in Java.

No ratings
283
30.11.2026
283
30.11.2026
No ratings
283
30.11.2026
Safe redirect via bot
О канале

LeetCode tasks and solutions in Java.

Подписчиков —
Тематика Technology
Ссылка @easy_java_task

We also recommend

Kekaton AI | Voiceover and voice clone
Kekaton AI | Voiceover and voice clone
Bot

AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.

Description

LeetCode task solutions in Java with emphasis on clean code and optimization. Topics: arrays, trees, graphs, dynamic programming. Ideal for technical preparation.

Latest posts

Java | LeetCode
Java | LeetCode
🔒Открыть пост
и посмотреть медиа
Задача: 269. Alien Dictionary Сложность: hard Есть новый инопланетный язык, который использует английский алфавит. Однако порядок букв в нем неизвестен. Вам дан список строк words из словаря инопланетного языка. Утверждается, что строки в words отсортированы лексикографически по правилам этого нового языка. Если это утверждение неверно и данное расположение строк в words не может соответствовать никакому порядку букв, верните "". В противном случае верните строку из уникальных букв нового инопланетного языка, отсортированных в лексикографическом порядке по правилам нового языка. Если существует несколько решений, верните любое из них. Пример: Input: words = ["wrt","wrf","er","ett","rftt"] Output: "wertf" 👨💻 Алгоритм: 1⃣Извлечение отношений порядка и создание списков смежности: Извлечь отношения порядка между буквами из слов. Вставить их в список смежности, обрабатывая случаи, когда одно слово является префиксом другого. 2⃣Подсчет числа входящих ребер: Подсчитать количество входящих ребер (in-degree) для каждой буквы. Построить исходящий список смежности и одновременно считать входящие ребра для каждой буквы. 3⃣Обход в ширину (BFS): Инициализировать очередь буквами с нулевым in-degree. Выполнять BFS, добавляя буквы в результат, когда их in-degree становится нулевым. Продолжать до тех пор, пока очередь не станет пустой. Проверить наличие циклов и вернуть результат. 😎 Решение: import java.util.*; class Solution { public String alienOrder(String[] words) { Map adjList = new HashMap(); Map inDegree = new HashMap(); for (String word : words) { for (char c : word.toCharArray()) { inDegree.put(c, 0); } } for (int i = 0; i < words.length - 1; i++) { String firstWord = words[i]; String secondWord = words[i + 1]; for (int j = 0; j < Math.min(firstWord.length(), secondWord.length()); j++) { char c = firstWord.charAt(j); char d = secondWord.charAt(j); if (c != d) { if (!adjList.containsKey(c)) { adjList.put(c, new HashSet()); } if (adjList.get(c).add(d)) { inDegree.put(d, inDegree.get(d) + 1); } break; } } if (secondWord.length() < firstWord.length() && firstWord.startsWith(secondWord)) { return ""; } } Queue queue = new LinkedList(); for (Map.Entry entry : inDegree.entrySet()) { if (entry.getValue() == 0) { queue.add(entry.getKey()); } } StringBuilder output = new StringBuilder(); while (!queue.isEmpty()) { char c = queue.poll(); output.append(c); if (adjList.containsKey(c)) { for (char d : adjList.get(c)) { inDegree.put(d, inDegree.get(d) - 1); if (inDegree.get(d) == 0) { queue.add(d); } } } } if (output.length() < inDegree.size()) { return ""; } return output.toString(); } } Ставь 👍 и забирай 📚 Базу знаний
Java | LeetCode
FAQ

Open Java | LeetCode in Telegram and press the Start button. No separate registration is required.

Yes. The service is designed to be straightforward: open the resource, follow the on-screen instructions and start using it.

No. You can use Java | LeetCode directly in Telegram unless the resource description says otherwise.

Access depends on the resource. Check the current information in Telegram after opening Java | LeetCode.

The exact features depend on the resource. Open Java | LeetCode to see its current functions, content and access conditions.

Reviews for channel Java | LeetCode

Log in to leave a review

Only registered users can share their opinion.

No reviews yet

Be the first to share your impression of this resource!

Similar resources

Loading
Switch to Light Theme
Home Catalog Collections Blog Login