上一页 1 ··· 11 12 13 14 15

2018年7月18日

303. Range Sum Query - Immutable

摘要: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: 阅读全文

posted @ 2018-07-18 08:59 猪猪🐷 阅读(78) 评论(0) 推荐(0)

334. Increasing Triplet Subsequence

摘要: Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array. Formally the function should: Note: Your algo 阅读全文

posted @ 2018-07-18 08:56 猪猪🐷 阅读(74) 评论(0) 推荐(0)

42. Trapping Rain Water

摘要: space optimization 这个计算就是多了个心眼, 用我妈的话来说, 用leftmax 时不用计算另一半, 是因为left Max比 right Max小的时候, 如果像上一个方法, 我们还是取两个中最小的 , 那么我们就不用知道rightMax具体是多少, 反正我们知道比left Ma 阅读全文

posted @ 2018-07-18 08:55 猪猪🐷 阅读(161) 评论(0) 推荐(0)

350. Intersection of Two Arrays II

摘要: Note: Each element in the result should appear as many times as it shows in both arrays. The result can be in any order. Follow up: What if the given 阅读全文

posted @ 2018-07-18 08:51 猪猪🐷 阅读(116) 评论(0) 推荐(0)

349. Intersection of Two Arrays

摘要: https://leetcode.com/problems/intersection-of-two-arrays/discuss/81969/Three-Java-Solutions Given two arrays, write a function to compute their inters 阅读全文

posted @ 2018-07-18 08:50 猪猪🐷 阅读(89) 评论(0) 推荐(0)

88. Merge Sorted Array

摘要: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and num 阅读全文

posted @ 2018-07-18 08:49 猪猪🐷 阅读(105) 评论(0) 推荐(0)

26. Remove Duplicates from Sorted Array

摘要: Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra spa 阅读全文

posted @ 2018-07-18 08:47 猪猪🐷 阅读(78) 评论(0) 推荐(0)

27. Remove Element

摘要: Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another ar 阅读全文

posted @ 2018-07-18 08:46 猪猪🐷 阅读(83) 评论(0) 推荐(0)

283. Move Zeroes

摘要: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Note: 阅读全文

posted @ 2018-07-18 08:44 猪猪🐷 阅读(102) 评论(0) 推荐(0)

189. Rotate Array

摘要: Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Example 2: Note: Try to come up as many solutions as you 阅读全文

posted @ 2018-07-18 08:43 猪猪🐷 阅读(79) 评论(0) 推荐(0)

18. 4Sum

摘要: Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique q 阅读全文

posted @ 2018-07-18 08:31 猪猪🐷 阅读(104) 评论(0) 推荐(0)

259. 3Sum Smaller

摘要: Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + 阅读全文

posted @ 2018-07-18 08:30 猪猪&#128055; 阅读(91) 评论(0) 推荐(0)

16. 3Sum Closest

摘要: Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the thr 阅读全文

posted @ 2018-07-18 08:29 猪猪&#128055; 阅读(71) 评论(0) 推荐(0)

15. 3Sum

摘要: 3 sum with/ without deduplication 3sum FB超级喜欢问这道题,所以务必sort和hash table的解法都烂熟于心,也问了时间和空间复杂度。4sum hashmap Given an array nums of n integers, are there el 阅读全文

posted @ 2018-07-18 08:28 猪猪&#128055; 阅读(112) 评论(0) 推荐(0)

167. Two Sum II - Input array is sorted

摘要: Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function 阅读全文

posted @ 2018-07-18 08:27 猪猪&#128055; 阅读(73) 评论(0) 推荐(0)

1. Two Sum

摘要: (hashmap && two pointers ) Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume th 阅读全文

posted @ 2018-07-18 08:26 猪猪&#128055; 阅读(89) 评论(0) 推荐(0)

69. Sqrt(x)

摘要: 5 1 5 Mid = 3 9 > 5 Right = 3 Left = 1 Mid = 2 注意这个退出条件 , 和其他 二分不太一样, 0 8 4 16 > 8 Right = 4 Mid = 2 Left = 0 2 * 2 < 8, 3 * 3 > 8 4. 8. 9 2. x. 3 Ret 阅读全文

posted @ 2018-07-18 08:25 猪猪&#128055; 阅读(102) 评论(0) 推荐(0)

240. Search a 2D Matrix II

摘要: 如果不是那种把所有的行都放在一起, 可以是一长串的 sorted numbers 的 话, 就用这种筛选法 We start search the matrix from top right corner, initialize the current position to top right c 阅读全文

posted @ 2018-07-18 08:24 猪猪&#128055; 阅读(90) 评论(0) 推荐(0)

74. Search a 2D Matrix

摘要: Use binary search. n * m matrix convert to an array => matrix[x][y] => a[x * m + y] an array convert to n * m matrix => a[x] =>matrix[x / m][x % m]; W 阅读全文

posted @ 2018-07-18 08:23 猪猪&#128055; 阅读(93) 评论(0) 推荐(0)

275. H-Index II

摘要: Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the resea 阅读全文

posted @ 2018-07-18 08:22 猪猪&#128055; 阅读(79) 评论(0) 推荐(0)

162. Find Peak Element

摘要: 这个题就是比较 mid 的时候, 和 mid + 1 index 的value 比较, 如果 mid + 1 的 value 比较大的话, 那么 local peak 肯定在 右边. it also covers the corner case , like 1 2 , then it return 阅读全文

posted @ 2018-07-18 08:21 猪猪&#128055; 阅读(115) 评论(0) 推荐(0)

540. Single Element in a Sorted Array

摘要: Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element 阅读全文

posted @ 2018-07-18 08:20 猪猪&#128055; 阅读(96) 评论(0) 推荐(0)

81. Search in Rotated Sorted Array II

摘要: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]). You are given a target value to search. If found... 阅读全文

posted @ 2018-07-18 08:19 猪猪&#128055; 阅读(83) 评论(0) 推荐(0)

33. Search in Rotated Sorted Array

摘要: comment 的几个 等号 ,要注意为啥这么写 题目一看就知道是binary search。所以关键点在于每次要能判断出target位于左半还是右半序列。解这题得先在纸上写几个rotated sorted array的例子出来找下规律。Rotated sorted array根据旋转得多少有两种情 阅读全文

posted @ 2018-07-18 08:19 猪猪&#128055; 阅读(99) 评论(0) 推荐(0)

154. Find Minimum in Rotated Sorted Array II

摘要: 和Search in Rotated Sorted Array II这题换汤不换药。同样当A[mid] = A[end]时,无法判断min究竟在左边还是右边。 3 1 2 3 3 3 3 3 3 3 3 1 2 3 但可以肯定的是可以排除A[end]:因为即使min = A[end],由于A[end 阅读全文

posted @ 2018-07-18 08:18 猪猪&#128055; 阅读(68) 评论(0) 推荐(0)

153. Find Minimum in Rotated Sorted Array

摘要: 先找出哪一段是sorted, 然后再根据这个去unsorted 的那部分找 min. 找 target 那道题是 先找出哪一段是sorted, 然后先看 target 在不在 sorted的 那一部分, 如果在, 就根据那一段继续二分, 如果不在, 去 unsorted 的那一段 二分去找。 这俩个 阅读全文

posted @ 2018-07-18 08:17 猪猪&#128055; 阅读(90) 评论(0) 推荐(0)

278. First Bad Version

摘要: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c 阅读全文

posted @ 2018-07-18 08:16 猪猪&#128055; 阅读(61) 评论(0) 推荐(0)

35. Search Insert Position

摘要: Index of the target or index of Smallest larger than the target 下面这几个例子都要考虑到才行, 面试的时候也是一样, 自己把这些情况都要考虑到, 面试的时候很可能不给你这么多的例子, 面试官可能指望你自己考虑周全, 把所有或者大部分的c 阅读全文

posted @ 2018-07-18 08:15 猪猪&#128055; 阅读(96) 评论(0) 推荐(0)

79. Word Search

摘要: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjac 阅读全文

posted @ 2018-07-18 08:10 猪猪&#128055; 阅读(86) 评论(0) 推荐(0)

17. Letter Combinations of a Phone Number

摘要: A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example: For static final, 阅读全文

posted @ 2018-07-18 08:09 猪猪&#128055; 阅读(109) 评论(0) 推荐(0)

784. Letter Case Permutation

摘要: Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible stri 阅读全文

posted @ 2018-07-18 08:08 猪猪&#128055; 阅读(151) 评论(0) 推荐(0)

216. Combination Sum III

摘要: Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be 阅读全文

posted @ 2018-07-18 08:07 猪猪&#128055; 阅读(86) 评论(0) 推荐(0)

40. Combination Sum II

摘要: Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb 阅读全文

posted @ 2018-07-18 08:06 猪猪&#128055; 阅读(87) 评论(0) 推荐(0)

39. Combination Sum

摘要: Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the 阅读全文

posted @ 2018-07-18 08:04 猪猪&#128055; 阅读(102) 评论(0) 推荐(0)

77. Combinations

摘要: 我写的 [1,4] is the same as [4,1] in the combination sense because in combination ,[1,4] is the same as [4,1], so we want to sort the array first and 1,1 阅读全文

posted @ 2018-07-18 08:01 猪猪&#128055; 阅读(118) 评论(0) 推荐(0)

22. Generate Parentheses

摘要: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: ( 阅读全文

posted @ 2018-07-18 07:48 猪猪&#128055; 阅读(112) 评论(0) 推荐(0)

46. Permutations

摘要: solution 2 : (1) used hashset to record used elements and pass the hashset for the next level on the current level, we need to do the backtrack recove 阅读全文

posted @ 2018-07-18 07:47 猪猪&#128055; 阅读(111) 评论(0) 推荐(0)

90. Subsets II

摘要: Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not conta 阅读全文

posted @ 2018-07-18 07:46 猪猪&#128055; 阅读(104) 评论(0) 推荐(0)

78. Subsets

摘要: (面经 Find the number of subsets which the sum of min value in subset and max value in subset smaller or equal to the given target) https://www.journald 阅读全文

posted @ 2018-07-18 07:34 猪猪&#128055; 阅读(118) 评论(0) 推荐(0)

上一页 1 ··· 11 12 13 14 15

导航