Cố Trường Ca
Senior Member
Có mấy bài bạch trạch trên matrix trư viết kiểu dfs vẫn ăn như thường màthấy ma trận mà còn đi viết dfs, mấy em nằm xuống bảnh cho 3 gậy sau nhớ![]()
![]()
Có mấy bài bạch trạch trên matrix trư viết kiểu dfs vẫn ăn như thường màthấy ma trận mà còn đi viết dfs, mấy em nằm xuống bảnh cho 3 gậy sau nhớ![]()
![]()
bạch trạch, duyệt cây, duyệt all path, topo thì dfsCó mấy bài bạch trạch trên matrix trư viết kiểu dfs vẫn ăn như thường mà
mở để lên thấy java cho input ntn thôi tắt đi coi phimbạch trạch, duyệt cây, duyệt all path, topo thì dfs
đường đi ngắn nhất, connected nodes, duyệt cây theo level thì bfs
...
chém gió thế chứ vào bài cũng làm bừa à![]()
![]()
chuyển ngôn ngữ khác thôi fency, jav khẩm dô, nhìn trông đã mệtmở để lên thấy java cho input ntn thôi tắt đi coi phimmảng 2 chiều nó cho list list vào đúng typing khổ râm luôn,![]()
Xem tệp đính kèm 2683939
phim gì thế mao, có truyện gì hay ko recommend đọc với nay chán vl, còn cơm hard chưa ăn mà nản quámở để lên thấy java cho input ntn thôi tắt đi coi phimmảng 2 chiều nó cho list list vào đúng typing khổ râm luôn,![]()
Xem tệp đính kèm 2683939
cơm hard code dài thôi chứ dễ. đọc editorial dc thêm 1 cách Binary search cũng hay, do ko cảm quan dc TC nên ko nghĩ cách đó xài dcphim gì thế mao, có truyện gì hay ko recommend đọc với nay chán vl, còn cơm hard chưa ăn mà nản quá
cơm hard code dài thôi chứ dễ. đọc editorial dc thêm 1 cách Binary search cũng hay, do ko cảm quan dc TC nên ko nghĩ cách đó xài dc![]()
coi liên xô chống us cũng phải khai saonhắn 3 câu rep 1 câu![]()
coi liên xô chống us cũng phải khai sao![]()

xem chỗ nào vậy
Thôi thôi được rồiChỉ là hơi thất vọng về bản thân thôi fence tại vì ko làm đc hard chứ rating của vozliz thì vẫn lụm đều đều
Đm đọc lộn constrain mới chết chứ.
LCCN - Loading React Appxem chỗ nào vậy
Thôi thôi được rồi![]()
(https://lccn.lbao.site/) 
LCCN - Loading React App(https://lccn.lbao.site/)
Vô đây mà predict
Q4 dễ hơn mà cắm đầu vô Q3 mệt quá![]()
class Solution {
public boolean carPooling(int[][] trips, int capacity) {
Map<Integer, Integer> map = new HashMap<>();
for (int[] trip: trips) {
map.put(trip[1], map.getOrDefault(trip[1], 0) + trip[0]);
map.put(trip[2], map.getOrDefault(trip[2], 0) - trip[0]);
}
int passengers = 0;
for (int i = 0; i <= 1000; i++) {
if (map.containsKey(i)) {
passengers += map.get(i);
}
if (passengers > capacity) return false;
}
return true;
}
}
class Solution {
public int[] fullBloomFlowers(int[][] flowers, int[] people) {
int[] ppl = Arrays.copyOf(people, people.length);
Arrays.sort(ppl);
Arrays.sort(flowers, (a, b) -> Arrays.compare(a, b));
PriorityQueue<Integer> heap = new PriorityQueue<>();
Map<Integer, Integer> map = new HashMap<>();
int idx = 0;
for (int p: ppl) {
while (idx < flowers.length && flowers[idx][0] <= p) {
heap.offer(flowers[idx][1]);
idx++;
}
while (!heap.isEmpty() && heap.peek() < p) {
heap.poll();
}
map.put(p, heap.size());
}
int[] ans = new int[people.length];
for (int i = 0; i < people.length; i++) {
ans[i] = map.get(people[i]);
}
return ans;
}
}
Bài 2 dùng sweep line điJava:class Solution { public boolean carPooling(int[][] trips, int capacity) { Map<Integer, Integer> map = new HashMap<>(); for (int[] trip: trips) { map.put(trip[1], map.getOrDefault(trip[1], 0) + trip[0]); map.put(trip[2], map.getOrDefault(trip[2], 0) - trip[0]); } int passengers = 0; for (int i = 0; i <= 1000; i++) { if (map.containsKey(i)) { passengers += map.get(i); } if (passengers > capacity) return false; } return true; } }Java:class Solution { public int[] fullBloomFlowers(int[][] flowers, int[] people) { int[] ppl = Arrays.copyOf(people, people.length); Arrays.sort(ppl); Arrays.sort(flowers, (a, b) -> Arrays.compare(a, b)); PriorityQueue<Integer> heap = new PriorityQueue<>(); Map<Integer, Integer> map = new HashMap<>(); int idx = 0; for (int p: ppl) { while (idx < flowers.length && flowers[idx][0] <= p) { heap.offer(flowers[idx][1]); idx++; } while (!heap.isEmpty() && heap.peek() < p) { heap.poll(); } map.put(p, heap.size()); } int[] ans = new int[people.length]; for (int i = 0; i < people.length; i++) { ans[i] = map.get(people[i]); } return ans; } }
class Solution:
def findTheLongestSubstring(self, s: str) -> int:
mask = 0
appearance = {0 : -1}
vowels = {'a': 1, 'e': 2, 'i': 3, 'o': 4, 'u': 5}
ans = 0
for i, char in enumerate(s):
if char in vowels:
mask ^= 1 << vowels[char]
if not mask in appearance:
appearance[mask] = i
else:
ans = max(ans, i - appearance[mask])
return ans
impl Solution {
pub fn find_the_longest_substring(s: String) -> i32 {
let encoding = &mut vec![0; 26];
let encoding = {
for (i, c) in [b'a', b'e', b'i', b'o', b'u'].iter().enumerate() {
encoding[(c - b'a') as usize] = 1 << i;
}
encoding.as_slice()
};
let mut earliest_pos = vec![-1; 32];
let (_, longest_len) = s.as_bytes().iter().enumerate().fold((0, 0), |(prefix_xor, longest_len), (i, &c)| {
let i = i as i32;
let prefix_xor = prefix_xor ^ encoding[(c - b'a') as usize];
let longest_len = match prefix_xor {
0 => i + 1,
_ =>
if earliest_pos[prefix_xor] == -1 {
earliest_pos[prefix_xor] = i;
longest_len
} else {
core::cmp::max(longest_len, i - earliest_pos[prefix_xor])
}
};
(prefix_xor, longest_len)
});
longest_len
}
}
sweep line là sao hả bác, các bước nó ntn.
var findTheLongestSubstring = function (s) {
const m = { 0: -1 }, n = s.length, k = 'aeoui';
let t = 0, ans = 0;
for (let i = 0; i < n; i++) {
const ch = s[i];
if (k.indexOf(ch) >= 0) {
t = t ^ (1 << k.indexOf(ch));
}
if (t in m) {
ans = Math.max(ans, i - m[t]);
} else {
m[t] = i;
}
}
return ans;
};