Comments (18)
Rick:https://leetcode-cn.com/u/inspiring-sinoussi1ht/
练习内容:数组(只出现一次的数字 多数元素 三数之和)截断句子
累计总数:92
今日增加:4
今日感悟:算法 好难 java是世界上最好的语言
from leetcoderank.
付有杰: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.
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.
付有杰:
复习内容: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.
热爱:https://leetcode-cn.com/u/callmew/
练习内容:每日一题
累计总数:206
今日增加:1
from leetcoderank.
付有杰
复习内容: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.
阿龙:https://leetcode-cn.com/u/a-long-k/
练习内容:数组
累计总数:78
今日增加:1
from leetcoderank.
游子:https://leetcode-cn.com/u/myenglandgirl/
练习内容:算法入门
累计总数:51
今日增加:2
from leetcoderank.
奥特曼:https://leetcode-cn.com/u/bei-xi-zi-du/
练习内容:有效括号
累计总数:27
今日增加:1
from leetcoderank.
小石头:https://leetcode-cn.com/u/xingorg1/
练习内容:栈
累计总数:81
今日增加:3
from leetcoderank.
帅土豆: https://leetcode-cn.com/u/boring-karektx/
练习内容: 截断句子
累计总数:48
今日增加:1
from leetcoderank.
柏仔 https://leetcode-cn.com/u/gu-yao-c/
练习内容:截断句子
累计总数:29
今日增加:1
from leetcoderank.
来一打可爱多 https://leetcode-cn.com/u/laiyidakeaiduo/
练习内容:977. 有序数组的平方
累计总数:30
今日增加:1
from leetcoderank.
平崽崽 https://leetcode-cn.com/u/ping-zhong-zi/
练习内容:初级算法 字符串 双指针
累计总数:28
今日增加:1
from leetcoderank.
走地鸡 https://leetcode-cn.com/u/xuezhichao19970719/
练习内容:1816. 截断句子
累计总数:334
今日增加:1
from leetcoderank.
zcq: https://leetcode-cn.com/u/zou-chang-qing/
练习内容:二分查找
累计总数:109
今日增加:1
from leetcoderank.
半橙汁 https://leetcode-cn.com/u/ban-cheng-zhi/
练习内容:剑指 Offer 25. 合并两个排序的链表【好绕。。。】
累计总数:28
今日增加:1
from leetcoderank.
陈伟霆:https://lleetcode-cn.com/u/will-6f/
练习内容:搜索插入位置 补
累计总数:30
今日增加:1
from leetcoderank.
Related Issues (20)
- 【每日打卡】2022-03-11 第122天 HOT 2
- 【每日打卡】2022-03-12 第123天 HOT 2
- 【每日打卡】2022-03-13 第124天 HOT 1
- 【每日打卡】2022-03-14 第125天 HOT 1
- 【每日打卡】2022-03-15 第126天 HOT 2
- 【每日打卡】2022-03-16 第127天 HOT 3
- 【每日打卡】2022-03-17 第128天 HOT 4
- 【每日打卡】2022-03-18 第129天 HOT 2
- 【每日打卡】2022-03-19 第130天 HOT 2
- 【每日打卡】2022-03-20 第131天 HOT 3
- 【每日打卡】2022-03-21 第132天 HOT 2
- 【每日打卡】2022-03-22 第133天 HOT 2
- 【每日打卡】2022-03-23 第134天 HOT 1
- 【每日打卡】2022-03-24 第135天
- 【每日打卡】2022-03-25 第136天 HOT 1
- 【每日打卡】2022-03-26 第137天
- 【每日打卡】2022-03-27 第138天
- 【每日打卡】2022-03-28 第139天
- 【每日打卡】2022-03-29 第140天
- 【每日打卡】2022-03-30 第141天 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leetcoderank.