Get Mystery Box with random crypto!

Leetcode in Java && MySQL

Logo of telegram channel leetcode_java — Leetcode in Java && MySQL L
Logo of telegram channel leetcode_java — Leetcode in Java && MySQL
Channel address: @leetcode_java
Categories: Blogs
Language: English
Subscribers: 272
Description from channel

If you have more efficient solution(less runtime) than mine, send it to @Z7akhongir . i will post it)
Second channel: @codeforces_java
Let's Develop Together!

Ratings & Reviews

4.00

3 reviews

Reviews can be left only by registered users. All reviews are moderated by admins.

5 stars

1

4 stars

1

3 stars

1

2 stars

0

1 stars

0


The latest Messages

2021-12-15 21:25:52 #N824. Goat Latin
problem link

#solution
class Solution {
public String toGoatLatin(String sentence) {
StringBuilder sb = new StringBuilder();
int count=1;
Set vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
for(String word: sentence.split(" ")){
if(vowels.contains(word.charAt(0)))
sb.append(word).append("ma");
else
sb.append(word.substring(1)).append(word.charAt(0)).append("ma");

for(int i=1; i<=count; i++)
sb.append("a");

count++;
sb.append(" ");
}

return sb.toString().trim();
}
}
11 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 18:25
Open / Comment
2021-12-13 09:48:58 #N2042. Check if Numbers Are Ascending in a Sentence
problem link

#solution
class Solution {
public boolean areNumbersAscending(String s) {
int temp = 0;
for(String word: s.split(" ")){
if(Character.isDigit(word.charAt(0))){
int num = Integer.parseInt(word);
if(num > temp) temp = num;
else return false;
}
}

return true;

}
}
15 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 06:48
Open / Comment
2021-12-13 09:19:30 #N2085. Count Common Words With One Occurrence
problem link

#solution
class Solution {
public int countWords(String[] words1, String[] words2) {
int count=0;

Map map1 = new HashMap<>();
Map map2 = new HashMap<>();
for(String word: words1)
map1.put(word, map1.getOrDefault(word, 0) +1);

for(String word: words2)
map2.put(word, map2.getOrDefault(word, 0) +1);

for (String word: words1)
if(map1.get(word) == 1 && map2.getOrDefault(word, 0) == 1) count++;

return count;
}
}
16 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 06:19
Open / Comment
2021-12-13 07:04:32 #N1446. Consecutive Characters
problem link

#solution
class Solution {
public int maxPower(String s) {
if(s.length() == 1) return 1;
int count = 0, power = 0;
char temp = s.charAt(0);

for(char ch: s.toCharArray()){
if(temp == ch) count++;
else{
count = 1;
temp = ch;
}
power = Math.max(power, count);
}

return power;
}
}
14 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 04:04
Open / Comment
2021-12-12 23:02:35 #N1974. Minimum Time to Type Word Using Special Typewriter
problem link

#solution
class Solution {
public int minTimeToType(String word) {
int time = 0;
char temp = 'a';

for(char ch: word.toCharArray()){
int time1 = Math.abs(ch-temp);
time = time + Math.min(time1, 26-time1) + 1;

temp = ch;
}

return time;
}
}
14 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 20:02
Open / Comment
2021-12-12 22:47:36 #N1935. Maximum Number of Words You Can Type
problem link

#solution
class Solution {
public int canBeTypedWords(String text, String brokenLetters) {
int broken[] = new int[26], count = 0;;

for(char ch: brokenLetters.toCharArray())
broken[ch-'a']++;

for(String word: text.split(" ")){
int countLength=0;

for(char ch: word.toCharArray())
if(broken[ch-'a'] == 0) countLength++;

if(countLength == word.length()) count++;
}

return count;
}
}
14 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 19:47
Open / Comment
2021-12-12 22:37:28 #N1880. Check if Word Equals Summation of Two Words
problem link

#solution
class Solution {
public boolean isSumEqual(String firstWord, String secondWord, String targetWord) {
int num1, num2, target;
num1 = func(firstWord);
num2 = func(secondWord);
target = func(targetWord);

return num1 + num2 == target;
}

public int func(String str){
int x=0;

for(char ch: str.toCharArray())
x = x*10 + (int)(ch-'a');

return x;
}
}
13 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 19:37
Open / Comment
2021-12-12 22:30:00 #N344. Reverse String
problem link

#solution
class Solution {
public void reverseString(char[] s) {
for(int i=0; i char tmp = s[i];
s[i] = s[s.length-1-i];
s[s.length-1-i] = tmp;
}
}
}
13 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 19:30
Open / Comment
2021-12-12 21:56:07 #N1768. Merge Strings Alternately
problem link

#solution
class Solution {
public String mergeAlternately(String word1, String word2) {
StringBuilder sb = new StringBuilder();

for(int i = 0; i if(word1.length()>i)
sb.append(word1.charAt(i));

if(word2.length()>i)
sb.append(word2.charAt(i));

}

return sb.toString();
}
}
14 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 18:56
Open / Comment
2021-12-12 21:50:16 #N657. Robot Return to Origin
problem link

#solution
class Solution {
public boolean judgeCircle(String moves) {
int[] count = new int[4];

for(char ch: moves.toCharArray()){
if(ch == 'R') count[0]++;
else if(ch == 'L') count[1]++;
else if(ch == 'U') count[2]++;
else count[3]++;
}

return count[0] - count[1] == 0 && count[2] - count[3] == 0;
}
}
13 views𝐉𝐚𝐤𝐡𝐨𝐧𝐠𝐢𝐫, 18:50
Open / Comment