随笔分类 -  LeetCode

这里是LeetCode算法学习
摘要:Given a 32-bit signed integer, reverse digits of an integer. Example: Example: Example: 代码如下: 阅读全文
posted @ 2018-04-13 10:38 alittlecomputer 阅读(127) 评论(0) 推荐(0)
摘要:最长回文子串 回文字符串的长度若是奇数,那么回文的中间一个单字符,两边对称。回文字符串的长度若是偶数,那么中间是两个字符一样,然后两边对称。 我们用的方法如下: 主要思路是找到一位然后向两边扩展,找到最大的长度。 阅读全文
posted @ 2018-04-12 09:51 alittlecomputer 阅读(138) 评论(0) 推荐(0)
摘要:代码如下: 这个有点复杂,看不太懂。 中位数是要把有序的数组分成两个等长的部分。 我们首先把数组A分成两个等长的部分: 数组A公有m个元素,所以公有m+1种分法。 而且我们知道,左边的长度为i,右边的长度为m-i。当i=0时左边是空的,当i=m时,右边是空的。即: 同样的,我们可以对B进行划分: 我 阅读全文
posted @ 2018-04-11 16:49 alittlecomputer 阅读(107) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. Example: Given "abcabcbb", the answer is "abc", which the lengt 阅读全文
posted @ 2018-04-11 11:12 alittlecomputer 阅读(154) 评论(0) 推荐(0)
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai 阅读全文
posted @ 2018-04-10 23:00 alittlecomputer 阅读(109) 评论(0) 推荐(0)
摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex 阅读全文
posted @ 2018-04-10 20:58 alittlecomputer 阅读(150) 评论(0) 推荐(0)
摘要:给定整数数组,如果有两个数之和是给定的数,那么返回两个数的下标。 每组输入只有一个解,同一个数不能用两次 例如:给定nums=[2,7,11,15],target=9, 因为nums[0]+nums[1]=9 返回[0,1] 我的答案: 看了别人优秀的答案: 使用HashMap,使的效率更高。 阅读全文
posted @ 2017-04-05 22:33 alittlecomputer 阅读(210) 评论(0) 推荐(0)