vicejuniordev
Senior Member
Có gì gửi đề cho ae trên đây thẩm nhé fenceTí mình có pv live coding này, hi vọng không có graph và dp![]()

via theNEXTvoz for iPhone
Có gì gửi đề cho ae trên đây thẩm nhé fenceTí mình có pv live coding này, hi vọng không có graph và dp![]()

class Solution:
def countConsistentStrings(self, allowed: str, words: List[str]) -> int:
hashset = set()
for i in allowed:
hashset.add(i)
res = len(words)
for w in words:
for l in w:
if l not in hashset:
res -= 1
break
return res
set(allowed) cũng được hehe ai biết đâubí thuật gì đâyJava:class Solution { public int countConsistentStrings(String allowed, String[] words) { int set =0; int cnt = words.length; for(char c:allowed.toCharArray()){ set = set|(1<<(c-'a'));//set (c-'a')th bit to 1 } for(String word:words){ for(char c: word.toCharArray()){ if((set&(1<<(c-'a')))==0)//check (c-'a')th bit { cnt--; break; } } } return cnt; } }

01 sinh 10, 10 sinh 11, 1 0 sinh vạn vật, mọi vật trong máy tính đều từ 1 0 mà rabí thuật gì đây![]()
Lập topic đưa cơm thêm đi, xong rồi ghim ở #1. Ai rảnh ngồi lội post mà kiếm cơm chứ,Nay hơi nhiều cơm rồi để mai ngồi kiếm cơm cho cả tuần luôn![]()

Chỗ của các vozliz chơi pro đi ra chỗ khác điLập topic đưa cơm thêm đi, xong rồi ghim ở #1. Ai rảnh ngồi lội post mà kiếm cơm chứ,![]()

Cơm thêm
Xin ít cơm thêm Medium aelàm hard riết mất não chán nản quá
![]()
class Solution:
def minimumLength(self, s: str) -> int:
hashmap = {}
res = len(s)
for i in s:
count_i = hashmap.get(i)
if not count_i:
hashmap[i] = 1
if count_i == 2:
res -= 2
hashmap[i] = 1
continue
if count_i is not None:
hashmap[i] += 1
return res
impl Solution {
pub fn count_consistent_strings(allowed: String, words: Vec<String>) -> i32 {
let bitset =
allowed.as_bytes().into_iter().
fold(0, |acc, &bc| acc | 1 << (bc - b'a') as u32);
let mut inconsistent_count = 0;
for word in &words {
let bytes = word.as_bytes();
let mut word_bitset = bitset;
for &bc in bytes {
word_bitset |= 1 << (bc - b'a') as u32;
if bitset != word_bitset {
inconsistent_count += 1;
break;
}
}
}
(words.len() - inconsistent_count) as i32
}
}
impl Solution {
pub fn count_consistent_strings(allowed: String, words: Vec<String>) -> i32 {
let bitset =
allowed.as_bytes().into_iter().
fold(0, |acc, &bc| acc | 1 << (bc - b'a') as u32);
let mut result =
words.iter().
filter(|&word| {
let (word_bytes, mut word_bitset) = (word.as_bytes(), bitset);
for &bc in word_bytes {
word_bitset |= 1 << (bc - b'a') as u32;
if word_bitset != bitset {
return false
}
}
true
}).
count();
result as i32
}
}
Chưa đc làm bảo vệ thì vẫn là vozliz thâu,

class Solution {
public:
int numberOfWeakCharacters(vector<vector<int>>& properties) {
sort(properties.begin(), properties.end(), [] (auto &a, auto &b) {
return a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]; // sort by increase attack, decrease defense
});
int ret = 0, max_defense = properties.back().back();
for (int i = properties.size() - 2; i >= 0; --i) {
if (max_defense > properties[i][1]) ret += 1;
else max_defense = properties[i][1];
}
return ret;
}
};
không chơi monotonic stack àC++:class Solution { public: int numberOfWeakCharacters(vector<vector<int>>& properties) { sort(properties.begin(), properties.end(), [] (auto &a, auto &b) { return a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]; // sort by increase attack, decrease defense }); int ret = 0, max_defense = properties.back().back(); for (int i = properties.size() - 2; i >= 0; --i) { if (max_defense > properties[i][1]) ret += 1; else max_defense = properties[i][1]; } return ret; } };
uhm, k cần monotonic stackkhông chơi monotonic stack à
Cũng đc mai fen, đang lũ lụt có cơm là húpCơm thêm có tính nền tảng khác ngoài leetcode không các bác. Em có một số bài hay nhưng lại rải rác ở một số nền tảng như codeforces, vnoi, vjudge, katis, ...
Lỡ làm k được up đề lên ae kêu ez ez chắc xóa nick luôn

ngồi nhà với làm test tâm lý khác nhau mà, chủ yếu tò mò thôi bác. làm daily với lúc làm contest thôi là thấy ngợp rLỡ làm k được up đề lên ae kêu ez ez chắc xóa nick luôn![]()
Rating khởi đầu là 1k5 mà fence
Làm thêm ít cơm thêm đi các fence
class Solution:
def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:
dx = min(ax2, bx2) - max(ax1, bx1)
dy = min(ay2, by2) - max(ay1, by1)
sd = dx*dy
if dx < 0 or dy < 0:
sd = 0
s1 = abs(ax2 - ax1)*abs(ay2 - ay1)
s2 = abs(bx2 - bx1)*abs(by2 - by1)
return s1 + s2 - sd
Có cách tìm overlapsed area dễ hơn là if else tay to thế này đó fencePython:class Solution: def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int: dx = 0 if bx1 >= ax1: if bx1 <= ax2 and bx2 >= ax2: dx = ax2 - bx1 if bx1 <= ax2 and bx2 <= ax2: dx = bx2 - bx1 else: if ax1 <= bx2 and ax2 >= bx2: dx = bx2 - ax1 if ax1 <= bx2 and ax2 <= bx2: dx = ax2 - ax1 dy = 0 if by1 >= ay1: if by1 <= ay2 and by2 >= ay2: dy = ay2 - by1 if by1 <= ay2 and by2 <= ay2: dy = by2 - by1 else: if ay1 <= by2 and ay2 >= by2: dy = by2 - ay1 if ay1 <= by2 and ay2 <= by2: dy = ay2 - ay1 s1 = abs(ax2 - ax1)*abs(ay2 - ay1) s2 = abs(bx2 - bx1)*abs(by2 - by1) sd = dx*dy return s1 + s2 - sd
ngón tay lên cơ luôn
ý thím là như này hở
dx = min(ax2, bx2) - max(ax1, bx1)
dy = min(ay2, by2) - max(ay1, by1)