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

  • Người tạo chủ đề Người tạo chủ đề _Gia_Cat_Luong_
  • Ngày bắt đầu Ngày bắt đầu
Trạng thái
Không mở để trả lời thêm.
khát khao intern lương 5m giống vozer2k4 :dribble::dribble:
Lỡ ôn leetcode thì nhắm top tier chứ nhảy vô mấy cty intern 5m thì vô làm gì bác. Giải được leetcode hard, thêm ít English+ ko trái ngành thì cứ mạnh dạn applied VNG (commit 15tr làm 2.5 ngày), Zalora ( như VNG nhưng được remote), fossil, marvel, .....
 
Lỡ ôn leetcode thì nhắm top tier chứ nhảy vô mấy cty intern 5m thì vô làm gì bác. Giải được leetcode hard, thêm ít English+ ko trái ngành thì cứ mạnh dạn applied VNG (commit 15tr làm 2.5 ngày), Zalora ( như VNG nhưng được remote), fossil, marvel, .....
Đứa e mới năm 2 ( gái, con cô em mẹ , gọi em mà thua gần 20 tuổi =)) ) định hướng nó cày như này, cũng đâu đó 4-500 bài leetcode, Ielts mục tiêu 7 chấm, gpa 3.9 gì đó mà hiện đang đi intern lương hẻo quá, có 3 triệu =)) Chắc do ở HN ít cty
 
Đứa e mới năm 2 ( gái, con cô em mẹ , gọi em mà thua gần 20 tuổi :LOL: ) định hướng nó cày như này, cũng đâu đó 4-500 bài leetcode, Ielts mục tiêu 7 chấm, gpa 3.9 gì đó mà hiện đang đi intern lương hẻo quá, có 3 triệu :LOL: Chắc do ở HN ít cty
xin info, t ref vô SG cho. :shame:
 
Học leetcode chỉ mong pass qua vòng 1 2 của big tech là mừng rồi. Mà dạo này big tech ít tuyển quá, đang chờ tới cuối năm xin khách hàng green card :too_sad::too_sad: ko thì bao giờ mới được đi pv

via theNEXTvoz for iPhone
 
Thank fence đã share phát nữa, ngồi giải 1 lèo phần number towers đã lụm xong còn mỗi bài 7 :ah: Đang ngồi làm nốt bài 7 :adore: DP chưa bao giờ dễ dàng đến thế :ah:

1. Number Tower,数塔​

  1. 118. Pascal's Triangle(Easy)、118. 杨辉三角(简单)
  2. 119. Pascal's Triangle II(Easy)、119. 杨辉三角 II(简单)
  3. 64. Minimum Path Sum(Medium)、64. 最小路径和(中等)
  4. 120. Triangle(Medium)、120. 三角形最小路径和(中等)
  5. 931. Minimum Falling Path Sum(Medium)、931. 下降路径最小和(中等)
  6. 1289. Minimum Falling Path Sum II(hard)、1289. 下降路径最小和 II(困难)
  7. 1301. Number of Paths with Max Score(hard)、1301. 最大得分的路径数目(困难)
 
Lỡ ôn leetcode thì nhắm top tier chứ nhảy vô mấy cty intern 5m thì vô làm gì bác. Giải được leetcode hard, thêm ít English+ ko trái ngành thì cứ mạnh dạn applied VNG (commit 15tr làm 2.5 ngày), Zalora ( như VNG nhưng được remote), fossil, marvel, .....

ở HN thấy k nhiều cty thuật lắm nên luyện dc 5m là mừng rồi :cold: mà có cách nào hết sợ hard k bác gặp mấy hard cố đâm vào đề k hiểu xog đọc solution còn bất lực hơn :cry:

Gửi từ Realme RMX3371 bằng vozFApp
 
C++:
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    int get_size(ListNode* l){
        int n = 0;
        while (l != NULL){
            n++;
            l = l->next;
        }
        return n;
    }
    int rec(ListNode*& l1, ListNode*& l2){
        if (l1 == NULL){
            return 0;
        }
        l1->val += l2->val + rec(l1->next,l2->next); // cộng có nhớ
        if (l1->val >= 10){
            l1->val -= 10;
            return 1;
        }
        else return 0;
    }
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        int n = get_size(l1), m = get_size(l2);
        if (n < m){
            swap(n,m);
            swap(l1,l2);
        }
        // làm cho len của 2 list bằng nhau
        while (n != m){
            m++;
            auto new_node = new ListNode(0,l2);
            l2 = new_node;
        }
        if (rec(l1,l2)) l1 = new ListNode(1,l1); // nếu như len(l1 + l2) > len(l1)
        return l1;
    }
};
 
Về lại medium là lại ngon :ah:
Tốc độ rất ổn, code phát ăn ngay :D

C#:
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int val=0, ListNode next=null) {
 *         this.val = val;
 *         this.next = next;
 *     }
 * }
 */
public class Solution {
    public ListNode AddTwoNumbers(ListNode l1, ListNode l2) {
        if(l1 == null)
            return l2;
        if(l2 == null)
            return l1;
       
        var length1 = findNodeLength(l1);
        var length2 = findNodeLength(l2);

        while(length1 != length2)
        {
            if(length1 > length2)
            {
                var temp = new ListNode(0);
                temp.next = l2;
                l2 = temp;
                length2 ++;
            }
            else
            {
                var temp = new ListNode(0);
                temp.next = l1;
                l1 = temp;
                length1 ++;
            }
        }

        var result = addTwoNumbers(l1, l2);
        if(result.number > 0)
        {
            return new ListNode(1, result.node);
        }

        return result.node;
    }

    private int findNodeLength(ListNode l)
    {
        var current = l;
        var length = 0;
        while(current != null)
        {
            length = length + 1;
            current = current.next;
        }

        return length;
    }

    private (int number, ListNode node) addTwoNumbers(ListNode l1, ListNode l2)
    {
        if(l1 == null && l2 == null)
            return (0, null);

        if(l1.next == null && l2.next == null)
        {
            var sum = l1.val + l2.val;
            return (sum/10, new ListNode( sum%10));
        }

        var nextNode = addTwoNumbers(l1.next, l2.next);
        var currentSum = l1.val + l2.val + nextNode.number;
        var result = (currentSum/10, new ListNode( currentSum%10, nextNode.node));
        return result;
    }
}
 
Sửa lần cuối:
Python:
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
   
def reverse_list(head):
    if head is None:
        return None
    curr = head
    while curr.next:
        new_head = curr.next
        curr.next = curr.next.next
        new_head.next = head
        head = new_head
    return head


class Solution:
    def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
        dummy = ListNode(0)
       
        l1 = reverse_list(l1)
        l2 = reverse_list(l2)

        p1 = l1
        p2 = l2
        memory = 0

        while p1 or p2 or memory:
            curr_digit = memory

            if p1:
                curr_digit += p1.val
                p1 = p1.next
            if p2:
                curr_digit += p2.val
                p2 = p2.next
           
            memory = curr_digit // 10
            curr_digit %= 10
           
            new_node = ListNode(curr_digit)
            new_node.next = dummy.next
            dummy.next = new_node
       
        return dummy.next
 
khởi động đầu tuần khá dễ
Python:
class Solution:
    def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
        expression = ""
        pt = l1
        while pt:
            expression += str(pt.val)
            pt = pt.next
        expression += "+"
        pt = l2
        while pt:
            expression += str(pt.val)
            pt = pt.next
        total = str(eval(expression))
        ans = ListNode(int(total[0]))
        pt = ans
        for i in range(1, len(total)):
            pt.next = ListNode(int(total[i]))
            pt = pt.next
            
        return ans
 
Bài hôm nay ko stack thì reverse thôi, viết nhanh cái stack :D
JavaScript:
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

function addTwoNumbers(a: ListNode | null, b: ListNode | null): ListNode | null {
    const s1: number[] = [], s2: number[] = [];
    while(a) {
        s1.push(a.val);
        a = a.next;
    }
    while (b) {
        s2.push(b.val);
        b = b.next;
    }
    let carry = 0, ans = null;
    while(s1.length || s2.length || carry) {
        const sum = (s1.pop() ?? 0 ) + (s2.pop() ?? 0) + carry;
        const newNode = new ListNode(sum % 10);
        newNode.next = ans;
        ans = newNode;
        carry = Math.floor(sum / 10);
    }
    return ans;
};
 
Dạo này rảnh rảnh định join cái này với mấy thím, cho mình hỏi mỗi ngày các thím chọn đề ở đâu vậy :oh:
 
Dạo này rảnh rảnh định join cái này với mấy thím, cho mình hỏi mỗi ngày các thím chọn đề ở đâu vậy :oh:
thím vô leetcode, đăng nhập thì thấy có hình ngọn lửa ở góc trên cùng bên phải đó, click vô đó là ra đề hôm đó
1689562909123.png


via theNEXTvoz for iPhone
 
C++:
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        return add(reverse(l1), reverse(l2));
    }

    ListNode* reverse(ListNode* l, ListNode* prev = nullptr) {
        auto next = l->next;
        l->next = prev;
        return next == nullptr ? l : reverse(next, l);
    }

    ListNode* add(ListNode* l1, ListNode* l2, int remain = 0, ListNode* prev = nullptr) {
        if (l1 == nullptr && l2 == nullptr && remain == 0) return prev;
        int val = remain + (l1 == nullptr ? 0 : l1->val) + (l2 == nullptr ? 0 : l2->val);
        return add((l1 == nullptr ? l1 : l1->next), (l2 == nullptr ? l2 : l2->next), val/10, new ListNode(val%10, prev));
    }
};
 
Sửa lần cuối:
JavaScript:
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var addTwoNumbers = function(l1, l2) {
    return ListNode.fromBigInt(l1.toBigInt() + l2.toBigInt());
};
ListNode.fromBigInt = function (v) {
    let result = new ListNode(Number(v % 10n));
    v /= 10n;
    while (v > 0n) {
        result = new ListNode(Number(v % 10n), result);
        v /= 10n;
    }
    return result;
};
ListNode.prototype.toBigInt = function () {
    let head = this;
    let result = BigInt(head.val);
    while (head.next) {
        head = head.next;
        result = result * 10n + BigInt(head.val);
    }
    return result;
};
 
Trạng thái
Không mở để trả lời thêm.

Thống kê chủ đề

Ngày tạo
_Gia_Cat_Luong_,
Người trả lời cuối
Vipluckystar,
Trả lời
17.755
Lượt xem
1.212.708
Quay lại
Lên đầu trang