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
🔒Открыть пост
и посмотреть медиа
Задача: 1258. Synonymous Sentences Сложность: medium Вам дан список эквивалентных пар строк synonyms, где synonyms[i] = [si, ti] означает, что si и ti являются эквивалентными строками. Вам также дан текст предложения. Верните все возможные синонимичные предложения, отсортированные лексикографически. Пример: Input: synonyms = [["happy","joy"],["sad","sorrow"],["joy","cheerful"]], text = "I am happy today but was sad yesterday" Output: ["I am cheerful today but was sad yesterday","I am cheerful today but was sorrow yesterday","I am happy today but was sad yesterday","I am happy today but was sorrow yesterday","I am joy today but was sad yesterday","I am joy today but was sorrow yesterday"] 👨💻 Алгоритм: 1⃣Построить граф синонимов, используя структуру данных, такую как Union-Find или просто с использованием DFS/BFS. 2⃣Пройти по каждому слову в предложении и найти все возможные синонимы. Сгенерировать все возможные комбинации предложений. 3⃣Отсортировать полученные предложения лексикографически. 😎 Решение: import java.util.*; public class Solution { public List generateSentences(List • > synonyms, String text) { Map graph = new HashMap(); for (List pair : synonyms) { graph.computeIfAbsent(pair.get(0), k -> new HashSet()).add(pair.get(1)); graph.computeIfAbsent(pair.get(1), k -> new HashSet()).add(pair.get(0)); } List words = Arrays.asList(text.split(" ")); List • > synonymGroups = new ArrayList(); for (String word : words) { synonymGroups.add(new ArrayList(findSynonyms(graph, word))); } List sentences = new ArrayList(); generate(sentences, synonymGroups, new StringBuilder(), 0); Collections.sort(sentences); return sentences; } private Set findSynonyms(Map graph, String word) { Set synonyms = new HashSet(); Stack stack = new Stack(); stack.push(word); while (!stack.isEmpty()) { String w = stack.pop(); if (synonyms.add(w)) { stack.addAll(graph.getOrDefault(w, Collections.emptySet())); } } return synonyms; } private void generate(List sentences, List • > groups, StringBuilder sentence, int index) { if (index == groups.size()) { sentences.add(sentence.toString().trim()); return; } int len = sentence.length(); for (String word : groups.get(index)) { sentence.append(" ").append(word); generate(sentences, groups, sentence, index + 1); sentence.setLength(len); } } } Ставь 👍 и забирай 📚 Базу знаний
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