Code Monkey home page Code Monkey logo

Comments (18)

DevWizardFeng avatar DevWizardFeng commented on May 30, 2024

Rick:https://leetcode-cn.com/u/inspiring-sinoussi1ht/
练习内容:数组(只出现一次的数字 多数元素 三数之和)截断句子
累计总数:92
今日增加:4
今日感悟:算法 好难 java是世界上最好的语言

from leetcoderank.

FuYouJ avatar FuYouJ commented on May 30, 2024

付有杰:https://leetcode-cn.com/u/fuyoujie2020/
复习内容:leetcode 141环形链表
public boolean hasCycle(ListNode head) { /* 常规思路:一直遍历链表,一边用map存储节点,一边检查 时间复杂度ON 空间复杂度 ON 优化思路:如果链表有环,那么可以看做原型赛道,两个人围着操场跑步,跑得快的人终究会有一刻会拉开跑得慢的人一圈 此时快慢相遇 快慢双指针思路难点在于 很容易空指针 时间复杂度O1:空间复杂度 ON */ //特判 没有节点或者只有一个节点视为没有环 if (head == null || head.next == null){ return false; } ListNode slow = head; ListNode fast = head; while (fast.next != null && fast.next.next != null){ slow = slow.next; fast = fast.next.next; if(slow == fast){ return true; } } return false; }

from leetcoderank.

FuYouJ avatar FuYouJ commented on May 30, 2024
public boolean hasCycle(ListNode head) {
        /*
         常规思路:一直遍历链表,一边用map存储节点,一边检查 时间复杂度ON 空间复杂度 ON
         优化思路:如果链表有环,那么可以看做原型赛道,两个人围着操场跑步,跑得快的人终究会有一刻会拉开跑得慢的人一圈 此时快慢相遇
         快慢双指针思路难点在于 很容易空指针 时间复杂度O1:空间复杂度 ON
         */
        //特判 没有节点或者只有一个节点视为没有环
        if (head == null || head.next == null){
            return false;
        }
        ListNode slow = head;
        ListNode fast = head;
        while (fast.next != null && fast.next.next != null){
            slow = slow.next;
            fast = fast.next.next;
            if(slow == fast){
                return true;
            }
        }
        return false;
    }

from leetcoderank.

FuYouJ avatar FuYouJ commented on May 30, 2024

付有杰:
复习内容:leetcode83:删除链表中的重复元素

 //删除排好序的链表里面的重复元素,只留下重复元素的一个
    public ListNode deleteDuplicates(ListNode head) {
        /*
         这里之所有哑巴节点直接指向head 而不是自己构造的节点 是因为有重复的元素也会保留一个,所以我保留head是一定可以的
         当然构造一个哑巴节点也可以 只不过返回时是dummy.next
         最开始我的写法没有else  每次删除之后便将指针后移,但是在遇到了1,1,1例子时预期是1我输出了1,1
         分析后发现 如果删除之后便将指针后移 而如果移动后指向的还是重复元素,便会漏删除,当然这可以在移动的时候继续判断
         但是循环体不就是在判断吗 
         错误写法:
          while (head != null && head.next != null){
            //保留当cur == next 删除next
            if (head.val == head.next.val){
                head.next = head.next.next;
            }
                head = head.next;
            
        }
        时间复杂度:因为要遍历所有的元素 所以时间复杂度是O(N)
        空间复杂度:O(1)
         */
        ListNode dummy = head;
        while (head != null && head.next != null){
            //保留当cur == next 删除next
            if (head.val == head.next.val){
                head.next = head.next.next;
            }else{
                head = head.next;
            }
        }
        return dummy;
    }

from leetcoderank.

callqh avatar callqh commented on May 30, 2024

热爱:https://leetcode-cn.com/u/callmew/
练习内容:每日一题
累计总数:206
今日增加:1

from leetcoderank.

FuYouJ avatar FuYouJ commented on May 30, 2024

付有杰
复习内容:leetcode234回文链表

// 1 2 3 4
    // 1 2 3
    public boolean isPalindrome(ListNode head) {
        if (head == null){
            return false;
        }
        ListNode slow = head;
        ListNode fast = head;
        //此种写法会导致slow节点永远停留在mid的前一个 见仁见智
        while (fast.next != null && fast.next.next != null){
            slow = slow.next;
            fast = fast.next.next;
        }
        ListNode mid = slow.next;
        slow.next = null;
        mid = reverse(mid);
        //假如链表长度是奇数 其实切开后两端链表不是一样的长 比如 1,2,1 切开= 1,2 和 1 但是他仍然是回文链表
        //也就是说 存在一种情况 比较完毕之后 返回结果是true 所以内部的比较逻辑就是 !=
        while (mid != null){
            if (head.val == mid.val){
                return false;
            }
            head = head.next;
            mid = mid.next;
        }
        return true;
    }

    private ListNode reverse(ListNode mid) {
        ListNode pre = null;
        while (mid != null){
            ListNode n = mid.next;
            mid.next = pre;
            pre = mid;
            mid = n;
        }
        return pre;
    }

from leetcoderank.

aflylong avatar aflylong commented on May 30, 2024

阿龙:https://leetcode-cn.com/u/a-long-k/
练习内容:数组
累计总数:78
今日增加:1

from leetcoderank.

MyEnglandGirl avatar MyEnglandGirl commented on May 30, 2024

游子:https://leetcode-cn.com/u/myenglandgirl/
练习内容:算法入门
累计总数:51
今日增加:2

from leetcoderank.

hanjianheng avatar hanjianheng commented on May 30, 2024

奥特曼:https://leetcode-cn.com/u/bei-xi-zi-du/
练习内容:有效括号
累计总数:27
今日增加:1

from leetcoderank.

xingorg1 avatar xingorg1 commented on May 30, 2024

小石头:https://leetcode-cn.com/u/xingorg1/
练习内容:栈
累计总数:81
今日增加:3

from leetcoderank.

LeXinFang avatar LeXinFang commented on May 30, 2024

帅土豆: https://leetcode-cn.com/u/boring-karektx/
练习内容: 截断句子
累计总数:48
今日增加:1

from leetcoderank.

EastStarCrow avatar EastStarCrow commented on May 30, 2024

柏仔 https://leetcode-cn.com/u/gu-yao-c/
练习内容:截断句子
累计总数:29
今日增加:1

from leetcoderank.

yantyt2022 avatar yantyt2022 commented on May 30, 2024

来一打可爱多 https://leetcode-cn.com/u/laiyidakeaiduo/
练习内容:977. 有序数组的平方
累计总数:30
今日增加:1

from leetcoderank.

Pingzhongzi avatar Pingzhongzi commented on May 30, 2024

平崽崽 https://leetcode-cn.com/u/ping-zhong-zi/
练习内容:初级算法 字符串 双指针
累计总数:28
今日增加:1

from leetcoderank.

yahaha-rf avatar yahaha-rf commented on May 30, 2024

走地鸡 https://leetcode-cn.com/u/xuezhichao19970719/
练习内容:1816. 截断句子
累计总数:334
今日增加:1

from leetcoderank.

zoucq avatar zoucq commented on May 30, 2024

zcq: https://leetcode-cn.com/u/zou-chang-qing/
练习内容:二分查找
累计总数:109
今日增加:1

from leetcoderank.

zxh008 avatar zxh008 commented on May 30, 2024

半橙汁 https://leetcode-cn.com/u/ban-cheng-zhi/
练习内容:剑指 Offer 25. 合并两个排序的链表【好绕。。。】
累计总数:28
今日增加:1

from leetcoderank.

hw1240230669 avatar hw1240230669 commented on May 30, 2024

陈伟霆:https://lleetcode-cn.com/u/will-6f/
练习内容:搜索插入位置 补
累计总数:30
今日增加:1

from leetcoderank.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.