• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
UsSam
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理

2014年3月11日

【Leetcode】Remove Duplicates from Sorted List
摘要: 题目:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.解题思路:设置两个指针CurrList和NewList,初始化为同一头指针,CurrList不断向链表尾部扫描,如果当前节点的值不是重复值,就将该节点接到NewList尾部。代码:/** * Definition for 阅读全文
posted @ 2014-03-11 19:09 UsSam 阅读(126) 评论(0) 推荐(0)
 
【Leetcode】Plus One
摘要: 题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.解题思路:要给原有容器表示的数加1,主要需要处理的就是进位的问题。由于是加1,因此只有在当前数字为9的时候采进位。如果在数组的第0个元素上还需要进位,那么就需要在该元素前面增加一个数字1。代码:class Solution {public: v... 阅读全文
posted @ 2014-03-11 16:42 UsSam 阅读(94) 评论(0) 推荐(0)
 
【Leetcode】Remove Element
摘要: 题目:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.解题思路:设置两个指针pa,pb,pa指针从0开始依次向n-1滑动,当pa指向的元素不是待删除的元素时,将pa指向的元素赋给pb指向的元素,同时pb向前滑动。代码:class Solution {publ 阅读全文
posted @ 2014-03-11 15:58 UsSam 阅读(110) 评论(0) 推荐(0)
 
 

公告


博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3