thảo luận Leetcode mỗi ngày

Câu cuối thấy bình thường.

Hôm nay PC hỏng code bằng tablet mà vẫn thừa hơn 30 phút. Tiếc là dính bug C1.
Tại lúc đầu cứ cố cắm đầu tối ưu cách dp(n^2) nên mất thời gian :beat_brick::beat_brick:. Câu 1 70% thằng nào chắc cx ăn 1 bọ hết :go::go:. Dạo gần đây thằng leetcode này ra lắm dp câu cuối thế :canny::canny:. Cho thằng khác ra đề xem nào. :cautious::cautious:
 
Tại lúc đầu cứ cố cắm đầu tối ưu cách dp(n^2) nên mất thời gian :beat_brick::beat_brick:. Câu 1 70% thằng nào chắc cx ăn 1 bọ hết :go::go:. Dạo gần đây thằng leetcode này ra lắm dp câu cuối thế :canny::canny:. Cho thằng khác ra đề xem nào. :cautious::cautious:

Vài tuần trước nhớ là có một câu liên quan đến bộ 3 rồi nên hôm nay thấy bộ 5 là nghĩ đến kỹ thuật xét điểm giữa ngay.
 
WawmAwM.png
contest ngày mai chủ nhật mới tới mà?
 
janDexM.jpg
xong daily hôm nay, đi coi world cup ngủ

Khẩm dô với C++
Untitled.png

C++:
struct tuples{
    int start;
    int end;
    int profit;
    tuples(){
        start = 0;
        end = 0;
        profit = 0;
    }
    tuples(int start, int end, int profit){
        this->start = start;
        this->end = end;
        this->profit = profit;
    }
    static tuples make_tp(int start, int end, int profit){
        return tuples(start, end, profit);
    }
    friend bool operator < (const tuples& lhs, const tuples& rhs) {
        return lhs.start < rhs.start;
    }
};
class Solution {
public:
    int jobScheduling(vector<int>& startTime, vector<int>& endTime, vector<int>& profit) {
        vector<tuples> v;
        int n = startTime.size();
        for(int i = 0; i < n; i++){
            v.push_back(tuples::make_tp(startTime[i], endTime[i], profit[i]));
        }
        sort(v.begin(), v.end());
        vector<int> dp(n);
        dp[n - 1] = v[n - 1].profit;
        for(int i = n - 2; i >= 0; i--){
            dp[i] = max(v[i].profit, dp[i + 1]);
            int left = i + 1;
            int right = n - 1;
            int nextJobs = -1;
            while(left <= right)
            {
                int mid = left + (right - left) / 2;
                if(v[mid].start >= v[i].end)
                {
                    right = mid - 1;
                    nextJobs = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }
            if(nextJobs != -1)
            {
                dp[i] = max(dp[i], dp[nextJobs] + v[i].profit);
            }
        }
        return dp[0];
    }
};
 
bác nào làm leetcode hôm nay chưa? em làm hashMap đếm trận thua rồi sort cái list.
thấy cách nào kiểu nobrain quá, hơi khó chịu mà ko biết có cách nào hay hơn ko
 
Hôm nay 2 dòng, chơi trick thì 1 dòng chắc cũng được mà lười. :censored:

Python:
def findWinners(self, matches: List[List[int]]) -> List[List[int]]:
  a, b = zip(*matches)
  return [sorted(set(a).difference(set(b))), sorted([i[0] for i in takewhile(lambda n: n[1]==1, Counter(b).most_common()[::-1])])]
 
bác nào làm leetcode hôm nay chưa? em làm hashMap đếm trận thua rồi sort cái list.
thấy cách nào kiểu nobrain quá, hơi khó chịu mà ko biết có cách nào hay hơn ko
Acceptted là có thể xem bài người khác đó bro. Vào xem thử bọn 100% nó làm như nào
 
Mình đang có job về C++ (Công ty làm khá thoải mái và vui vẻ) lương từ 750$ - 2000$. Bác nào muốn apply thì inbox em nhé. Em hướng dẫn để nội dung để ôn tập phỏng vấn nhé
 
Topic này dead rồi à :eek:
var uniqueOccurrences = function(arr) {
let map = {}
const a = arr.length
for (let i=0;i<a;i++) if (map[arr]=== undefined) map[arr] = 1
else map[arr] ++
return (Object.values(map)).length === (Array.from(new Set( Object.values(map)))).length
};
 
41UWGpo.png
hôm nay ngày cuối tháng cho bài quá dễ

Time complexity O(n), space O(n^2) nhé

JavaScript:
function uniqueOccurrences(arr: number[]): boolean {
    let map =  new Map<number, number>();
    for(let i of arr){
        map.set(i, (map.get(i) || 0) + 1);
    }
    let set = new Set<number>();
    map.forEach((values)=>{
       set.add(values);
    });
    return set.size == map.size;
};

Java:
class Solution {
    public boolean uniqueOccurrences(int[] arr) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i : arr){
            map.put(i, map.getOrDefault(i, 0) + 1);
        }
        HashSet<Integer> set = new HashSet<>(map.values());
        return set.size() == map.size();
    }
}
 
41UWGpo.png
hôm nay ngày cuối tháng cho bài quá dễ

Time complexity O(n), space O(n^2) nhé

JavaScript:
function uniqueOccurrences(arr: number[]): boolean {
    let map =  new Map<number, number>();
    for(let i of arr){
        map.set(i, (map.get(i) || 0) + 1);
    }
    let set = new Set<number>();
    map.forEach((values)=>{
       set.add(values);
    });
    return set.size == map.size;
};

Java:
class Solution {
    public boolean uniqueOccurrences(int[] arr) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i : arr){
            map.put(i, map.getOrDefault(i, 0) + 1);
        }
        HashSet<Integer> set = new HashSet<>(map.values());
        return set.size() == map.size();
    }
}
cách này là space O(n) chứ nhỉ
 
Back
Top