и посмотреть медиа
Golang | LeetCode
и посмотреть медиа
LeetCode tasks in Golang. Solutions with code and explanations.
LeetCode tasks in Golang. Solutions with code and explanations.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
Channel with solutions to popular LeetCode tasks in Go. Focus on optimized algorithms, efficient memory usage, and idiomatic code. Helps prepare for technical interviews in companies that use Golang.
Задача: 423. Reconstruct Original Digits from English Сложность: medium Дана строка s, содержащая неупорядоченное английское представление цифр от 0 до 9, верните цифры в порядке возрастания. Пример: Input: s = "owoztneoer" Output: "012" 👨💻 Алгоритм: 1⃣Подсчитайте количество каждого символа в строке s с помощью хэш-таблицы или массива, чтобы определить количество каждого символа. 2⃣Используйте уникальные символы, присутствующие только в одном числе (например, 'z' для 0, 'w' для 2, 'u' для 4, 'x' для 6, 'g' для 8), чтобы определить количество этих цифр в строке. Затем определите количество остальных цифр, вычитая уже найденные цифры. 3⃣Соберите найденные цифры в строку в порядке возрастания и верните результат. 😎 Решение: package main import ( "strings" ) func originalDigits(s string) string { count := make(map[rune]int) for _, letter := range s { count[letter]++ } out := make([]int, 10) out[0] = count['z'] out[2] = count['w'] out[4] = count['u'] out[6] = count['x'] out[8] = count['g'] out[3] = count['h'] - out[8] out[5] = count['f'] - out[4] out[7] = count['s'] - out[6] out[9] = count['i'] - out[5] - out[6] - out[8] out[1] = count['n'] - out[7] - 2*out[9] var output strings.Builder for i := 0; i < 10; i++ { for j := 0; j < out[i]; j++ { output.WriteString(string(i + '0')) } } return output.String() } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!