Java
#kiss #princple KISS (Keep It Simple, Stupid)- bu dizayn tamoyili bo‘lib, u shuni aytadiki: tizimlar va dizaynlar imkon qadar soddaligi kerak. Ya’ni, ortiqcha murakkablikdan iloji boricha qochish kerak, chunki soddalik foydalanuvchilar uchun tizimni oson…
Please open Telegram to view this post
VIEW IN TELEGRAM
😁3
Q1. Lexicographically Smallest String After Reverse
Status: Medium @leetcode7 @contest @leetcode #leetcode
Status: Medium @leetcode7 @contest @leetcode #leetcode
Leetcode contest
Q1. Lexicographically Smallest String After Reverse Status: Medium @leetcode7 @contest @leetcode #leetcode
Status: Accepted ✅
Code: Kotlin🐨
@leetcode7 @leetcode8 @contest @leetcode #contest #leetcode
Code: Kotlin
class Solution {
public String lexSmallest(String s) {
int n = s.length();
String smallest = s;
for (int k = 1; k <= n; k++) {
String firstK = new StringBuilder(s.substring(0, k)).reverse().toString() + s.substring(k);
if (firstK.compareTo(smallest) < 0) {
smallest = firstK;
}
String lastK = s.substring(0, n - k) +
new StringBuilder(s.substring(n - k)).reverse().toString();
if (lastK.compareTo(smallest) < 0) {
smallest = lastK;
}
}
return smallest;
}
}
@leetcode7 @leetcode8 @contest @leetcode #contest #leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
Problem: Q2. Maximize Sum of Squares of Digits 🖖
Status: Medium🧟♂️ @leetcode @leetcode7 @contest #biweekly
Status: Medium
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Problem: Q2. Maximize Sum of Squares of Digits 🖖 Status: Medium 🧟♂️ @leetcode @leetcode7 @contest #biweekly
class Solution {
public String maxSumOfSquares(int num, int sum) {
int drevantor = sum;
if (sum > 9 * num) return "";
if (sum < 0) return "";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < num; i++) {
int digit = Math.min(9, sum);
sb.append(digit);
sum -= digit;
}
if (sum > 0) return "";
return sb.toString();
}
}#leetcode @contest @leetcode #biweekly
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM