摘要: (238)-(Product of Array Except Self )-(计算数组内每一个数,除了自己以外的乘机)-(技巧强,左边乘积和右边乘机分开,空间换时间)//就是先从左至右扫描,记录前i?1个数的乘积,//第二遍扫描时,从右至左,将乘积再乘以后i+1位的乘积。 //空间复杂度o(n)pu... 阅读全文
posted @ 2015-07-25 21:18 爱吃萝卜干 阅读(110) 评论(0) 推荐(0) 编辑
摘要: (237)-(Delete Node in a Linked List )-(给出待删除的节点,把他变成他后面的)-(理解题意以及停止点的细心)/** * Definition for singly-linked list. * public class ListNode { * int v... 阅读全文
posted @ 2015-07-25 20:59 爱吃萝卜干 阅读(90) 评论(0) 推荐(0) 编辑
摘要: (233)-(Number of Digit One)-(计算出从1-n中1的个数)-(归纳总结,我觉得+=的地方好奇怪啊)public class Solution { //每10个数, 有一个个位是1, //每100个数, 有10个十位是1, //每1000个数, 有1... 阅读全文
posted @ 2015-07-25 20:40 爱吃萝卜干 阅读(1644) 评论(0) 推荐(0) 编辑
摘要: (206)-(Reverse Linked List)-(???????)-(??,????)public class Solution { public ListNode reverseList(ListNode head) { if(head==null ||head.n... 阅读全文
posted @ 2015-07-25 20:07 爱吃萝卜干 阅读(129) 评论(0) 推荐(0) 编辑
摘要: (160)-(Intersection of Two Linked Lists)-(尾巴相同的list)-(不仅仅是求交集,理解题目的意思很重要)public class Solution{ public ListNode getIntersectionNode(ListNode headA,... 阅读全文
posted @ 2015-07-25 20:06 爱吃萝卜干 阅读(97) 评论(0) 推荐(0) 编辑
摘要: (3)-(Longest Substring Without Repeating Characters)-(找不重复的最长子串的长度)-(用HashMap和HashSet进行查重)//the longest substring without repeating letters for "abcab... 阅读全文
posted @ 2015-07-25 19:45 爱吃萝卜干 阅读(206) 评论(0) 推荐(0) 编辑
摘要: (231)-(Power of Two)-(判断一个整数他是不是2的多少次方)-(一直除以2就好了,注意1和0这种特殊情况)//Given an integer,//write a function to determine if it is a power of twopublic class S... 阅读全文
posted @ 2015-07-25 19:33 爱吃萝卜干 阅读(123) 评论(0) 推荐(0) 编辑
摘要: (220)-(Contains Duplicate III)-(判断数组中是否位置差至多为k时,值差最多为t)-(特殊解法,用treeset中的floor和ceiling)//Given an array of integers, //find out whether there are two d... 阅读全文
posted @ 2015-07-25 19:31 爱吃萝卜干 阅读(217) 评论(0) 推荐(0) 编辑
摘要: (219)-(Contains Duplicate II)-(判断数组中出现重复值的两个元素,位置差最多为k)-(HashSet及时删除元素)//Given an array of integers and an integer k,//find out whether there there ar... 阅读全文
posted @ 2015-07-25 19:30 爱吃萝卜干 阅读(129) 评论(0) 推荐(0) 编辑
摘要: (217)-(Contains Duplicate)-(数组中是否包含重复值)-(HashSet进行处理)//Given an array of integers, find if the array contains any duplicates.//Your function should re... 阅读全文
posted @ 2015-07-25 19:27 爱吃萝卜干 阅读(105) 评论(0) 推荐(0) 编辑
摘要: (7)-(Reverse Integer)-(将整数按位反转成另外一个整数,考虑溢出)-(知道最大整数和最小整数值)//Reverse digits of an integer.//Example1: x = 123, return 321//Example2: x = -123, return -... 阅读全文
posted @ 2015-07-25 19:26 爱吃萝卜干 阅读(112) 评论(0) 推荐(0) 编辑
摘要: (88)-(Merge Sorted Array )-(将两个有序的数组合并成同一个数组nums1)-(还是归并排序的最后一步)//You may assume that nums1 has enough space //(size that is greater or equal to m + n... 阅读全文
posted @ 2015-07-25 19:26 爱吃萝卜干 阅读(93) 评论(0) 推荐(0) 编辑
摘要: (5)-(Longest Palindromic Substring )-(最长回文字串)-(特殊解法,)//Given a string S, find the longest palindromic substring in S.//You may assume that the maximum... 阅读全文
posted @ 2015-07-25 19:25 爱吃萝卜干 阅读(84) 评论(0) 推荐(0) 编辑
摘要: (6)-(ZigZag Conversion)-(字符串按照某种规则进行输出)-(StringBuffer存各行内容)//The string "PAYPALISHIRING" is written in a zigzag pattern //on a given number of rows li... 阅读全文
posted @ 2015-07-25 19:25 爱吃萝卜干 阅读(89) 评论(0) 推荐(0) 编辑
摘要: (4)-(Median of Two Sorted Arrays)-(找两个有序数组的中位数)-(归并排序的最后一步,两个数组合并)//There are two sorted arrays nums1 and nums2 of size m and n respectively. //Find t... 阅读全文
posted @ 2015-07-25 19:19 爱吃萝卜干 阅读(174) 评论(0) 推荐(0) 编辑
摘要: (2)-(Add Two Numbers)-(将两个ListNode表示的整树进行按位加)-(ListNode的遍历)Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Output: 7 -> 0 -> 8//这里考察单链表的尾插法://首先,申请内存final_ans//r_... 阅读全文
posted @ 2015-07-25 19:14 爱吃萝卜干 阅读(465) 评论(0) 推荐(0) 编辑
摘要: (1)-(Two SUM-在数组中找到两个数,他们的和为给定的数)-(数组遍历)Input: numbers={2, 7, 11, 15}, target=9Output: index1=1, index2=2//非常低效的二层循环遍历,勉强能够实现这个效果//都初始化为-1,如果找不到,返回两个-... 阅读全文
posted @ 2015-07-25 19:12 爱吃萝卜干 阅读(93) 评论(0) 推荐(0) 编辑