上一主题 下一主题
ScriptCat,新一代的脚本管理器脚本站,与全世界分享你的用户脚本油猴脚本开发指南教程目录
返回列表 发新帖
楼主: 李恒道 - 

【当前无排名】挑战leetcode进入前1w名

[复制链接]
  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-8-26 17:42:37 | 显示全部楼层

    https://leetcode.cn/problems/merge-two-sorted-lists/submissions/558715098/?envType=study-plan-v2&envId=top-100-liked
    简单题,链表合并

    var mergeTwoLists = function (list1, list2) {
        let head = { next: null }
        const ret = head
        while (list1 != null && list2 != null) {
            if (list1.val < list2.val) {
                head.next = list1
                list1 = list1.next
                head = head.next
            } else {
                head.next = list2
                list2 = list2.next
                head = head.next
            }
        }
    
        do {
            if (list2) {
                head.next = list2
                list2 = list2.next
                head = head.next
            }
            if (list1) {
                head.next = list1
                list1 = list1.next
                head = head.next
            }
    
        } while (list1 != null || list2 != null);
        return ret.next
    };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复
    订阅

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-8-26 17:42:59 | 显示全部楼层
    王一之 发表于 2024-8-26 16:57
    我提议新开一个catcode平台,重新进行排名

    这样我就可以给自己改成第一了!
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-8-26 18:02:37 | 显示全部楼层

    https://leetcode.cn/problems/add-two-numbers/submissions/558720843/?envType=study-plan-v2&envId=top-100-liked
    简单题

    var addTwoNumbers = function (l1, l2) {
        let add = 0
        let head = {
            next: null
        }
        let ret = head
        while (l1 != null || l2 != null) {
            const num1 = l1?.val ?? 0
            const num2 = l2?.val ?? 0
            let total = num1 + num2 + add
            add =0
            if(total>=10){
                total-=10
                add=1
            }
            head.next = {
                val: total,
                next: null
            }
            head = head.next
            l1 = l1?.next;
            l2 = l2?.next
        }
        if (add !== 0) {
            head.next = {
                val: add,
                next: null
            }
        }
        return ret.next
    };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-8-26 18:23:04 | 显示全部楼层

    https://leetcode.cn/problems/remove-nth-node-from-end-of-list/submissions/558725242/?envType=study-plan-v2&envId=top-100-liked
    边界有点难控制,其他没了

    var removeNthFromEnd = function (head, n) {
        if(head.next==null&&n==1){
            return null
        }
        let fast = head
        let slow = head
        for (let index = 0; index < n; index++) {
            fast = fast.next
        }
        if(fast==null){
            return head.next
        }
        while (fast?.next != null) {
            slow = slow.next
            fast = fast.next
        }
        slow.next=slow?.next?.next??null
        return head
    };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-8-26 18:38:24 | 显示全部楼层

    https://leetcode.cn/problems/swap-nodes-in-pairs/submissions/558728046/?envType=study-plan-v2&envId=top-100-liked
    简单交换题

        var swapPairs = function (head) {
            if(head?.next==null){
                return head
            }
            const ret = {
                next:null
            }
            let setHead=ret
    
            while (head?.next != null) {
                let first = head
                let last = head.next
                head = last.next
                first.next = last.next;
                last.next = first
                setHead.next=last
                setHead=first
            }
            return ret.next
        };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-8-26 18:49:59 | 显示全部楼层

    https://leetcode.cn/problems/number-of-steps-to-reduce-a-number-to-zero/submissions/558730132/
    简单题水一下换换心情

    var numberOfSteps = function (num) {
        let times = 0
        while (num != 0) {
            num = num % 2 == 0 ? num / 2 : num - 1;
            times++
        }
        return times
    };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-8-27 05:13:42 | 显示全部楼层

    https://leetcode.cn/problems/reverse-nodes-in-k-group/submissions/558836129/?envType=study-plan-v2&envId=top-100-liked
    还算可以
    边界判断蒙了

    var reverseKGroup = function (head, k) {
      let fast = head;
      let slow = head;
      let ret = { next: null };
      let chain = ret;
      while (slow != null) {
        let isJump=false
        for (let index = 0; index < k; index++) {
          fast = fast.next;
          if (fast == null) {
            if(index!=k-1){
                isJump=true
            }
            break;
          }
        }
        if (isJump) {
          chain.next = slow;
          break;
        }
        let last = null;
        let first = slow;
        while (slow != fast) {
          let next = slow.next;
          slow.next = last;
          last = slow;
          slow = next;
        }
        chain.next = last;
        chain = first;
      }
    
      return ret.next;
    };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-9-3 02:14:06 | 显示全部楼层

    https://leetcode.cn/problems/copy-list-with-random-pointer/submissions/560906494/?envType=study-plan-v2&envId=top-100-liked
    凹了一晚上才凹出来
    思路歪了...

    var copyRandomList = function (head) {
        if(head==null){
            return null
        }
        let chainPoint = head
        do {
            const val = chainPoint.val
            const next = chainPoint.next
            const newNode = {
                val,
                next
            }
            chainPoint.next = newNode
            chainPoint = chainPoint?.next?.next
        } while (chainPoint != null);
        let coptPoint = head
        while (coptPoint != null) {
            coptPoint.next.random = coptPoint?.random?.next ?? null
            coptPoint = coptPoint?.next?.next
        }
        let newChain = {
            next: null
        }
        const ret = newChain
        while (head != null) {
            newChain.next = head.next;
            newChain = newChain.next
            head.next = head?.next?.next ?? null
            head = head.next
        }
        return ret.next
    };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-9-3 04:02:45 | 显示全部楼层

    https://leetcode.cn/problems/sort-list/?envType=study-plan-v2&envId=top-100-liked
    打一波归序,但是快慢指针控制的不好
    边界过多了

    var sortList = function (head, end = undefined) {
        if (head?.next == end) {
            return head
        }
        let slow = head?.next;//第二段开头
        let first = head;//第一段结尾
        let fast = head?.next;//第二个结尾
        if (fast != end) {
            fast = fast?.next
            if (fast?.next != end) {
                while (fast != end) {
                    slow = slow?.next;
                    fast = fast?.next?.next;
                    if (fast?.next == end) {
                        fast = fast?.next
                        break;
                    }
                }
            }else{
                fast = fast?.next
            }
        }
    
        let china1 = sortList(first, slow)
        let china2 = sortList(slow, end)
        let headptr = {
            next: null
        }
        const ptr = headptr
        while (china1 != slow || china2 != fast) {
            if (china1 != slow && china2 != fast) {
                const num1 = china1?.val;
                const num2 = china2?.val;
                if (num1 < num2) {
                    headptr.next = china1
                    china1 = china1.next;
                } else {
                    headptr.next = china2
                    china2 = china2.next;
                }
            } else {
                headptr.next = china1 != slow ? china1 : china2
                if (china1 != slow) {
                    china1 = china1.next;
                } else {
                    china2 = china2.next;
                }
            }
            headptr = headptr.next
        }
        headptr.next = end ?? null
        return ptr.next
    
    };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    695

    主题

    5646

    回帖

    6521

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6521

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-9-3 04:05:52 | 显示全部楼层

    https://leetcode.cn/problems/middle-of-the-linked-list/submissions/560909018/
    简单题直接秒

    var middleNode = function (head) {
        let slow = head
        let fast = head
        while (fast != null&&fast.next!=null) {
            fast = fast?.next;
            slow = slow.next
            fast = fast?.next;
        }
        return slow
    };
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

    发表回复

    本版积分规则

    快速回复 返回顶部 返回列表