LeetCode Weekly Contest 481 Discussion and Solution
Priyanshu Chaurasiya
2 months ago
Priyanshu Chaurasiya
2 months ago

Join the conversation by signing in below!
| Problem | Difficulty | Points | Status |
|---|
| 1 | Easy | 3 | Solved |
| 2 | Medium | 4 | Solved |
| 3 | Hard | 6 | Unsolved |
| 4 | Hard | 6 | Unsolved |
class Solution {
public int mirrorDistance(int n) {
int num = n;
int rev = 0;
while(num > 0){
int digit = num % 10;
rev = rev * 10 + digit;
num /= 10;
}
return Math.abs(n - rev);
}
}class Solution {
public long minCost(String s, int[] cost) {
int n = cost.length;
Map<Character, Long> map = new HashMap<>();
for(int i = 0; i < n; i++){
char ch = s.charAt(i);
map.put(ch, (long) map.getOrDefault(ch, 0L) + cost[i]);
}
long maxVal = 0;
for(Long val : map.values()){
maxVal = Math.max(maxVal, val);
}
long ans = 0 - maxVal;
for(Long val : map.values()){
ans += val;
}
return ans;
}
}No comments yet, Start the conversation!