- 博客(173)
- 收藏
- 关注
原创 leetcode刷题笔记--6. ZigZag Conversion
6. ZigZag ConversionThe string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A ...
2020-03-12 20:56:43
351
原创 leetcode刷题笔记(Golang)--4. Median of Two Sorted Arrays
4. Median of Two Sorted ArraysThere 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 should be O(log (m+n)...
2020-03-09 21:18:16
388
原创 leetcode刷题笔记(Golang)--389. Find the Difference
389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find t...
2020-03-07 20:07:27
381
原创 leetcode刷题笔记(Golang)--387. First Unique Character in a String
387. First Unique Character in a StringGiven a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.Examples:s = “leetcode”return 0.s = “love...
2020-03-07 19:58:32
317
原创 leetcode刷题笔记(Golang)--377. Combination Sum IV
377. Combination Sum IVGiven an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]...
2020-03-07 19:47:16
241
原创 leetcode刷题笔记(Golang)--367. Valid Perfect Square
367. Valid Perfect SquareGiven a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example ...
2020-03-07 19:11:14
131
原创 leetcode刷题笔记(Golang)--350. Intersection of Two Arrays II
350. Intersection of Two Arrays IIGiven two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2,2]Example 2:Input: nums1 = [4,9,5],...
2020-03-06 22:29:03
147
原创 leetcode刷题笔记(Golang)--349. Intersection of Two Arrays
349. Intersection of Two ArraysGiven two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input: nums1 = [4,9,5], nums...
2020-03-06 22:05:13
195
原创 leetcode刷题笔记(Golang)--342. Power of Four
342. Power of FourGiven an integer (signed 32 bits), write a function to check whether it is a power of 4.Example 1:Input: 16Output: trueExample 2:Input: 5Output: falseFollow up: Could you sol...
2020-03-06 21:03:30
156
原创 leetcode刷题笔记(Golang)--344. Reverse String
344. Reverse StringWrite a function that reverses a string. The input string is given as an array of characters char[].Do not allocate extra space for another array, you must do this by modifying th...
2020-03-06 20:52:29
177
原创 leetcode刷题笔记(Golang)--334. Increasing Triplet Subsequence
330. Patching ArrayGiven an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, ksuch that...
2020-03-06 20:15:51
172
原创 leetcode刷题笔记(Golang)--328. Odd Even Linked List
Odd Even Linked ListGiven a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You sh...
2020-03-06 19:35:36
135
原创 leetcode刷题笔记(Golang)--326. Power of Three
326. Power of ThreeGiven an integer, write a function to determine if it is a power of three.Example 1:Input: 27Output: trueExample 2:Input: 0Output: falseExample 3:Input: 9Output: trueExam...
2020-03-06 17:41:25
154
原创 leetcode刷题笔记(Golang)--322. Coin Change
322. Coin ChangeYou are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that...
2020-03-06 17:33:34
183
原创 leetcode刷题笔记(Golang)--313. Super Ugly Number
313. Super Ugly NumberWrite a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k.Example:Input: ...
2020-03-06 12:39:48
158
原创 leetcode刷题笔记(Golang)--304. Range Sum Query 2D - Immutable
Range Sum Query 2D - ImmutableGiven a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).Range Su...
2020-03-06 00:52:33
163
原创 leetcode刷题笔记(Golang)--303. Range Sum Query - Immutable
303. Range Sum Query - ImmutableGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> ...
2020-03-05 22:53:01
153
原创 leetcode刷题笔记(Golang)--300. Longest Increasing Subsequence
300. Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest inc...
2020-03-05 22:04:56
187
原创 leetcode刷题笔记(Golang)--299. Bulls and Cows
299. Bulls and CowsYou are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, yo...
2020-03-05 21:33:40
220
原创 leetcode刷题笔记(Golang)--290. Word Pattern
290. Word PatternGiven a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty wor...
2020-03-05 21:10:52
187
原创 leetcode刷题笔记(Golang)--287. Find the Duplicate Number
Find the Duplicate NumberGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is on...
2020-03-05 20:49:30
135
原创 leetcode刷题笔记(Golang)--283. Move Zeroes
283. Move ZeroesGiven 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:Input: [0,1,0,3,12]Output: [1,3,12,0,0]...
2020-03-05 20:21:21
175
原创 leetcode刷题笔记(Golang)--279. Perfect Squares
279. Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.Example 1:Input: n = 12Output: 3Explanation: 12 = 4 + ...
2020-03-05 19:35:51
135
原创 leetcode刷题笔记(Golang)--275. H-Index II
275. H-Index IIGiven an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.According to the ...
2020-03-04 20:10:29
109
原创 leetcode刷题笔记(Golang)--274. H-Index
274. H-IndexGiven an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.According to the definition of h-index on Wiki...
2020-03-04 19:27:36
131
原创 leetcode刷题笔记(Golang)--268. Missing Number
268. Missing NumberGiven an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.Example 1:Input: [3,0,1]Output: 2Example 2:Input: [9,6,4,2,3...
2020-03-04 19:00:20
110
原创 leetcode刷题笔记(Golang)--264. Ugly Number II
264. Ugly Number IIWrite a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.Example:Input: n = 10Output: 12Explanation: 1, 2, 3, 4,...
2020-03-04 18:38:35
104
原创 leetcode刷题笔记(Golang)--263. Ugly Number
263. Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.Example 1:Input: 6Output: trueExplana...
2020-03-04 13:06:22
146
原创 leetcode刷题笔记(Golang)--258. Add Digits
258. Add DigitsGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.Example:Input: 38Output: 2Explanation: The process is like: 3 + 8 = 11, 1 + 1 = ...
2020-03-04 10:40:39
110
原创 leetcode刷题笔记(Golang)--257. Binary Tree Paths
257. Binary Tree PathsGiven a binary tree, return all root-to-leaf paths.Note: A leaf is a node with no children.Example:Input:1/ 2 35Output: [“1->2->5”, “1->3”]Explanation: ...
2020-03-04 10:13:53
155
原创 leetcode刷题笔记(Golang)--242. Valid Anagram
242. Valid AnagramGiven two strings s and t , write a function to determine if t is an anagram of s.Example 1:Input: s = “anagram”, t = “nagaram”Output: trueExample 2:Input: s = “rat”, t = “car”...
2020-03-04 01:37:45
202
原创 leetcode刷题笔记(Golang)--240. Search a 2D Matrix II
240. Search a 2D Matrix IIWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left t...
2020-03-04 01:28:49
189
原创 leetcode刷题笔记(Golang)--238. Product of Array Except Self
238. Product of Array Except SelfGiven an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Exam...
2020-03-03 20:04:14
158
原创 leetcode刷题笔记(Golang)--237. Delete Node in a Linked List
237. Delete Node in a Linked ListWrite a function to delete a node (except the tail) in a singly linked list, given only access to that node.Given linked list – head = [4,5,1,9], which looks like fo...
2020-03-03 19:25:06
112
原创 leetcode刷题笔记(Golang)--236. Lowest Common Ancestor of a Binary Tree
236. Lowest Common Ancestor of a Binary TreeGiven a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest com...
2020-03-03 19:02:49
271
原创 leetcode刷题笔记(Golang)--235. Lowest Common Ancestor of a Binary Search Tree
235. Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikiped...
2020-03-03 18:58:24
225
原创 leetcode刷题笔记(Golang)--234. Palindrome Linked List
234. Palindrome Linked ListGiven a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you...
2020-03-03 16:44:37
132
原创 leetcode刷题笔记(Golang)--230. Kth Smallest Element in a BST
230. Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST’s total elements...
2020-03-03 16:33:50
239
原创 leetcode刷题笔记(Golang)--229. Majority Element II
229. Majority Element IIGiven an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Note: The algorithm should run in linear time and in O(1) space.Example 1:Input: [3,...
2020-03-03 13:02:10
211
原创 leetcode刷题笔记(Golang)--228. Summary Ranges
228. Summary RangesGiven a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: [“0->2”,“4->5”,“7”]Explanation: 0,1,2 form a cont...
2020-03-03 10:06:29
165
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人