摘要: QuestionGiven an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the... 阅读全文
posted @ 2015-09-11 23:26 树獭君 阅读(140) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].SolutionSimilar with Pascal's Triangle. Note... 阅读全文
posted @ 2015-09-11 23:06 树獭君 阅读(212) 评论(0) 推荐(0) 编辑
摘要: QuestionGivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,... 阅读全文
posted @ 2015-09-11 08:47 树獭君 阅读(352) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].S... 阅读全文
posted @ 2015-09-11 07:56 树獭君 阅读(148) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven 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 doe... 阅读全文
posted @ 2015-09-11 05:51 树獭君 阅读(126) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra spa... 阅读全文
posted @ 2015-09-11 05:42 树獭君 阅读(140) 评论(0) 推荐(0) 编辑
摘要: QuestionRotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Solution... 阅读全文
posted @ 2015-09-11 05:19 树獭君 阅读(166) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant dig... 阅读全文
posted @ 2015-09-11 04:24 树獭君 阅读(165) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in... 阅读全文
posted @ 2015-09-11 04:03 树獭君 阅读(137) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that ... 阅读全文
posted @ 2015-09-11 03:53 树獭君 阅读(183) 评论(0) 推荐(0) 编辑
摘要: Solution 1Naive wayFirst, sort the array using Arrays.sort in Java. Than, scan once to find the majority element. Time complexity O(nlog(n)) 1 public ... 阅读全文
posted @ 2015-09-11 03:07 树獭君 阅读(151) 评论(0) 推荐(0) 编辑