leetcode处女作
闲来无事【真的吗?你确定→_→
在leetcode上刷了一道题。费时一小时,也是醉了。谨以此文,纪念我的伟大成果。【呵呵
题目是找出非排序数组中缺少的最小正整数。要求时间复杂度O(n),空间复杂度为常数。
首先考虑把数组排序。发现没有排序算法满足要求,放弃。
想到找出数组中最大的数和最小的数,定义k值,从最小的数开始,在数组中依次查找,有对应的即k++,没有,返回k值,即为所求。如果min到max都存在,返回max+1。
期间忘记考虑数组长度为0的情况,报错;比较时的逻辑错误;print语句忘删等各种情况报错。
不敢说收获颇丰,但起码开始了第一步。fighting!
leetcode处女作的更多相关文章
- 我为什么要写LeetCode的博客?
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
随机推荐
- kafka的安装和使用
简单说kafka是一个高吞吐的分部式消息系统,并且提供了持久化. kafka的架构 • producer:消息生存者• consumer:消息消费者• broker:kafka集群的server,负责 ...
- POJ1006 - Biorhythms(中国剩余定理)
题目大意 略...有中文... 题解 就是解同余方程组 x≡(p-d)(mod 23) x≡(e-d)(mod 28) x≡(i-d)(mod 33) 最简单的中国剩余定理应用.... 代码: #in ...
- JavaScript- The Good Parts Chapter 3 Objects
Upon a homely object Love can wink.—William Shakespeare, The Two Gentlemen of Verona The simple type ...
- Android文字的阴影效果
<!-- android:shadowDx 阴影的水平偏移量 即往右移的距离 --> <!-- android:shadowDy 阴影的垂直偏移量 即往下移的距离--> < ...
- layer (jQuery弹出层插件)使用
$(".delete").click(function(){ var work_name = $(this).data('name'); var item_id = $(this) ...
- 如何给Windows添加自动启动的程序
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:如何给Windows添加自动启动的程序.
- Cocos2d-x学习笔记之Cocos2d-x开发环境搭建
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Cocos2d-x源码包下载地址: http://cocos2d-x.org/projects/cocos2d-x/ ...
- FindWindowEx
procedure CloseGameSver(); var H1, h2: HWND; begin H1 := FindWindow('TForm1', nil); h2 := FindWindow ...
- linux下lighttpdserver的具体安装步骤 以及对flv流媒体的支持配置
准备条件: a,创建/usr/local/lighttpd文件夹,用于安装lighttpd b,创建lighttpd用户password为lighttpd账号,用于lighttpd的启动用户 c,安装 ...
- centos 7 修改主机名称
hostnamectl --static set-hostname <host-name> 参考资料 http://www.centoscn.com/CentOS/config/2014/ ...