

- Главная
- Каталог
- Интернет технологии
- Java | LeetCode
Статистика канала
Полная статистикаchevron_right
Input: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "coding"
Output: 1{}
import java.util.*;
class Solution {
public int shortestWordDistance(String[] wordsDict, String word1, String word2) {
List<Integer> indices1 = new ArrayList<>();
List<Integer> indices2 = new ArrayList<>();
for (int i = 0; i < wordsDict.length; i++) {
if (wordsDict[i].equals(word1)) {
indices1.add(i);
}
if (wordsDict[i].equals(word2)) {
indices2.add(i);
}
}
int shortestDistance = Integer.MAX_VALUE;
for (int index : indices1) {
int x = Collections.binarySearch(indices2, index);
if (x < 0) {
x = -x - 1;
}
if (x < indices2.size()) {
shortestDistance = Math.min(shortestDistance, indices2.get(x) - index);
}
if (x > 0 && !indices2.get(x - 1).equals(index)) {
shortestDistance = Math.min(shortestDistance, index - indices2.get(x - 1));
}
}
return shortestDistance;
}
}{}
Ставь 👍 и забирай 📚 Базу знаний
Input: a = 2, b = [3]
Output: 8{}
public class Solution {
public int getSum(int a, int b) {
int x = Math.abs(a), y = Math.abs(b);
if (x < y) return getSum(b, a);
int sign = a > 0 ? 1 : -1;
if (a * b >= 0) {
while (y != 0) {
int carry = (x & y) << 1;
x ^= y;
y = carry;
}
} else {
while (y != 0) {
int borrow = ((~x) & y) << 1;
x ^= y;
y = borrow;
}
}
return x * sign;
}
}{}
Ставь 👍 и забирай 📚 Базу знаний
Input: prices = [1,3,2,8,4,9], fee = 2
Output: 8{}
public class Solution {
public int maxProfit(int[] prices, int fee) {
int cash = 0, hold = -prices[0];
for (int price : prices) {
cash = Math.max(cash, hold + price - fee);
hold = Math.max(hold, cash - price);
}
return cash;
}
}{}
Ставь 👍 и забирай 📚 Базу знаний
Input: num = 23
Output: "1000"{}
public class Solution {
public String encode(int num) {
if (num == 0) return "";
return Integer.toBinaryString(num - 1);
}
}{}
Ставь 👍 и забирай 📚 Базу знаний
Input: root = [10,5,15,3,7,null,18], low = 7, high = 15
Output: 32{}
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode() {}
TreeNode(int val) { this.val = val; }
TreeNode(int val, TreeNode left, TreeNode right) {
this.val = val;
this.left = left;
this.right = right;
}
}
class Solution {
public int rangeSumBST(TreeNode root, int low, int high) {
if (root == null) return 0;
if (root.val < low) return rangeSumBST(root.right, low, high);
if (root.val > high) return rangeSumBST(root.left, low, high);
return root.val + rangeSumBST(root.left, low, high) + rangeSumBST(root.right, low, high);
}
}{}
Ставь 👍 и забирай 📚 Базу знанийОтзывы канала
- Добавлен: Сначала новые
- Добавлен: Сначала старые
- Оценка: По убыванию
- Оценка: По возрастанию
Каталог Телеграм-каналов для нативных размещений
Java | LeetCode — это Telegam канал в категории «Интернет технологии», который предлагает эффективные форматы для размещения рекламных постов в Телеграмме. Количество подписчиков канала в 7.0K и качественный контент помогают брендам привлекать внимание аудитории и увеличивать охват. Рейтинг канала составляет 6.0, количество отзывов – 1, со средней оценкой 5.0.
Вы можете запустить рекламную кампанию через сервис Telega.in, выбрав удобный формат размещения. Платформа обеспечивает прозрачные условия сотрудничества и предоставляет детальную аналитику. Стоимость размещения составляет 2237.76 ₽, а за 8 выполненных заявок канал зарекомендовал себя как надежный партнер для рекламы в TG. Размещайте интеграции уже сегодня и привлекайте новых клиентов вместе с Telega.in!
Вы снова сможете добавить каналы в корзину из каталога
Комментарий