leetcode-day1

Two Sum

Brute Force: time O(n^2) space O(1)

Hash Map: time O(n) space O(n)

Add Two Numbers

Unconsidered:

[1]+[9,9]-> after l1 ends and l2 ends, there is still one carry

Struct initiation in C++: new ListNode(0)

if (temp->val==0) temp==0 

change to 

if (temp->val==0) {

l4 = l3;

while(l4->next!=NULL){

if(l4 ->next==temp) l4->next = NULL;

else l4=l4->next;

}

}

first one simply let temp points to NULL, but doesn't change the front node's next pointer, so l4 is needed as the front node then set its next to NULL.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • <center>#1 Two Sum</center> link Description:Given an arr...
    铛铛铛clark阅读 6,600评论 0 3
  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 14,349评论 0 33
  • 开始的,没等到结局。 季节催促回忆。 转过街角,路灯跳跃了几下 提醒我暗夜和黎明的距离 远方的风吹向远方 并没有为...
    木木和桓桓阅读 1,547评论 0 2
  • 我 曾张开双臂 尝试着揽她入怀 她 却羞着躲避 只来往于我心怀 我 失落地观望 当她碰壁消散时 她 宁静地注视 在...
    龙孟秋阅读 1,241评论 0 3
  • 晚上9点多,眼皮打战,累得不要不要的,硬撑着看手机,时间一过发现,有了上夜班的精神,,11点,要睡,不睡,精神好的...
    小言微微阅读 1,787评论 0 0