随笔分类 -  算法练习

摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo 阅读全文
posted @ 2016-10-17 13:46 没离开过 阅读(532) 评论(0) 推荐(0)
摘要:如 321 反转 123 120 反转21 注意处理最后的零,以及负数情况 ,最后就是溢出情况了 阅读全文
posted @ 2016-10-16 20:29 没离开过 阅读(1235) 评论(0) 推荐(0)
摘要:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh 阅读全文
posted @ 2016-10-11 21:00 没离开过 阅读(305) 评论(0) 推荐(0)
摘要:用一个 hash table 来存储字符以及字符对应下标。 s[j] 在[i,j)中存在重复的字符,那么可以将 i 移到 重复字符下标的下一个位置。 例如:‘abcefcda' i一开始为0,j向后移动,当j=5时(即s[5]=c)判断得出有重复元素,i就 应该赋值为tmp['c']中的位置(注意t 阅读全文
posted @ 2016-10-10 23:48 没离开过 阅读(1286) 评论(0) 推荐(0)
摘要:这种方法是遍历2次,时间复杂度为O(n2) 空间复杂度为O(1) 下面是使用数组键值存储,简单的hash-table 来达到时间复杂度为O(n) 空间复杂度为O(n) 阅读全文
posted @ 2016-10-08 18:58 没离开过 阅读(256) 评论(0) 推荐(0)
摘要:主要看异常处理情况: 1.前后空格的处理 2.+,- 符号的处理 3.要求字符串后有数字以外的字符仍然能够正常工作,例如‘452fjse' 输出 452 4.超过int 型数值范围处理 最大值2147483647 和最小值 -2147483648 。 阅读全文
posted @ 2016-10-08 12:48 没离开过 阅读(249) 评论(0) 推荐(0)
摘要:leetcode 上的题目 Determine whether an integer is a palindrome. Do this without extra space. 由于不能使用额外空间,所以不能把数字转化为字符串后进行比较。因为这样空间复杂度将为线性。 leetcode给出了几点提示 阅读全文
posted @ 2016-10-08 11:32 没离开过 阅读(3929) 评论(1) 推荐(0)