![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
程序猿柴
这个作者很懒,什么都没留下…
展开
-
Solution of Find Pivot Index
Given an array of integers nums, write a method that returns the “pivot” index of this array.We define the pivot index as the index where the sum of the numbers to the left of the index is equal to the sum of the numbers to the right of the index.If no s原创 2020-05-19 16:21:23 · 240 阅读 · 0 评论 -
Solution of Reverse Only Letters
Given a string S, return the “reversed” string where all characters that are not a letter stay in the same place, and all letters reverse their positions.Example 1:Input: “ab-cd”Output: “dc-ba”Example 2:Input: “a-bC-dEf-ghIj”Output: “j-Ih-gfE-dCba”E原创 2020-05-18 11:56:29 · 199 阅读 · 0 评论 -
Solution of Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:Input: 1 1/ \ / 2 3 2 3原创 2020-05-17 12:22:48 · 105 阅读 · 0 评论 -
Solution of Reshape the Matrix
In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-dimensional array, and two positive integers r and c represent原创 2020-05-16 12:58:22 · 110 阅读 · 0 评论 -
Solution of Range Sum Query - Immutable
Given 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) -> 1sumRange(2, 5) -> -1sumRange(0, 5) -> -3Note:You may assume that the array doe原创 2020-05-15 10:16:25 · 103 阅读 · 0 评论 -
Solution of Sum With Multiplicity
Given an integer array A, and an integer target, return the number of tuples i, j, k such that i < j < k and A[i] + A[j] + A[k] == target.As the answer can be very large, return it modulo 10^9 + 7.Example 1:Input: A = [1,1,2,2,3,3,4,4,5,5], targe原创 2020-05-14 10:23:51 · 112 阅读 · 0 评论 -
Solution of Check Permutation LCCI
Given two strings,write a method to decide if one is a permutation of the other.Example 1:Input: s1 = “abc”, s2 = “bca”Output: trueExample 2:Input: s1 = “abc”, s2 = “bad”Output: falseNote:0 <= len(s1) <= 1000 <= len(s2) <= 100Idea of原创 2020-05-13 11:06:25 · 132 阅读 · 0 评论 -
Solution of Valid Perfect Square
Given 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 1:Input: 16Output: trueExample 2:Input: 14Output: falseIdeas of solutionIt’原创 2020-05-12 11:50:05 · 143 阅读 · 0 评论 -
Solution of Add to Array-Form of Integer
For a non-negative integer X, the array-form of X is an array of its digits in left to right order. For example, if X = 1231, then the array form is [1,2,3,1].Given the array-form A of a non-negative integer X, return the array-form of the integer X+K.E原创 2020-05-11 12:16:27 · 104 阅读 · 0 评论 -
Solution of Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I’ll tell you whether the number is higher or lower.You call a pre-defined API guess(int num) which re原创 2020-05-10 12:32:21 · 117 阅读 · 0 评论 -
Solution of Letter Tile Possibilities
You have a set of tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make.Example 1:Input: “AAB”Output: 8Explanation: The possible sequences are “A”, “B”, “AA”, “AB”, “BA”原创 2020-05-09 10:40:18 · 138 阅读 · 0 评论 -
Solution of Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1:Input:[[0,0,0],[0,1,0],[0,0,0]]Output:[[0,0,0],[0,1...原创 2020-05-08 12:06:59 · 145 阅读 · 0 评论 -
Solution of Minimum Absolute Difference
Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements.Return a list of pairs in ascending order(with respect to pairs), each pai...原创 2020-05-07 09:55:37 · 111 阅读 · 0 评论 -
Solution of LCOF
Draw 5 cards at random from playing CARDS to see if it is a coincidence, that is, if the 5 CARDS are consecutive.2 ~ 10 is the number itself, A is 1, J is 11, Q is 12, K is 13, and xiao wang and xiao ...原创 2020-05-06 11:36:01 · 145 阅读 · 0 评论 -
Solution of Insert Into Bits LCCI
You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i. You can assume that the bits j through i hav...原创 2020-05-05 12:06:16 · 122 阅读 · 0 评论 -
Solution of Implement strStr()
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = “hello”, needle = “ll”Output: 2Example 2:In...原创 2020-05-04 09:00:34 · 92 阅读 · 0 评论 -
Solution of Factorial Zeros LCCI
Write an algorithm which computes the number of trailing zeros in n factorial.Example 1:Input: 3Output: 0Explanation: 3! = 6, no trailing zero.Example 2:Input: 5Output: 1Explanation: 5! = 120,...原创 2020-05-03 11:46:57 · 140 阅读 · 0 评论 -
Solution of Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns true when it is a perfect...原创 2020-05-02 11:04:20 · 119 阅读 · 0 评论 -
Solution of Reverse String
Write 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 the input array in-pla...原创 2020-05-01 11:12:39 · 104 阅读 · 0 评论 -
Solution of Find the Distance Value Between Two Arrays
Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.The distance value is defined as the number of elements arr1[i] such that there is not any ...原创 2020-04-30 11:32:24 · 134 阅读 · 0 评论 -
如何上传代码到github
笔者最近开始做leetcode的练习,并且想要把解题思路和代码上传到github上,那么该怎么上传我们的代码呢。1. 注册github账号如果我们想将代码上传到github上,我们必须先创建一个属于自己的github账号。那么这里附上github的官方网站 https://github.com/那么这里附上笔者的github链接,有兴趣的读者可以访问并进行指导,https://github....原创 2020-04-29 20:43:47 · 742 阅读 · 0 评论 -
Solution of Bitwise AND of Numbers Range
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.Example 1:Input: [5,7]Output: 4Example 2:Input: [0,1]Output: 0Ideas...原创 2020-04-29 11:44:27 · 74 阅读 · 0 评论 -
Solution of String to URL LCCI
Write a method to replace all spaces in a string with ‘%20’. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the “true” length o...原创 2020-04-28 10:32:32 · 110 阅读 · 0 评论 -
Solution for Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.Example 1:Input: 5Output: TrueExplanation:The binary representation...原创 2020-04-27 12:38:59 · 70 阅读 · 0 评论 -
Solution of Find N Unique Integers Sum up to Zero
Given an integer n, return any array containing n unique integers such that they add up to 0.Example 1:Input: n = 5Output: [-7,-1,1,3,4]Explanation: These arrays also are accepted [-5,-1,1,2,3] , ...原创 2020-04-26 12:51:31 · 124 阅读 · 0 评论 -
Solution of Check If It Is a Straight Line
Check If It Is a Straight LineYou are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plan...原创 2020-04-25 13:32:40 · 169 阅读 · 0 评论 -
Solution of Missing Number LCCI
An array contains all the integers from 0 to n, except for one number which is missing. Write code to find the missing integer. Can you do it in O(n) time?Note: This problem is slightly different fr...原创 2020-04-24 12:18:28 · 95 阅读 · 0 评论 -
Solution of K-diff Pairs in an Array
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in...原创 2020-04-23 11:27:25 · 69 阅读 · 0 评论 -
Solution of Maximum Length of Repeated Subarray
Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation:The repeated subarray wit...转载 2020-04-22 17:06:10 · 82 阅读 · 0 评论 -
Simple implementation of self divisor using the go language
Self divisor is the number that can be divided by every digit it contains.For example, 128 is a self-divisor because 128%1 == 0, 128%2 == 0, 128%8 == 0.Also, it is not allowed to include 0’s in the ...原创 2020-04-21 12:20:20 · 146 阅读 · 0 评论 -
The Implementation of Rotating Numbers
We call a number X a good number, and if each of its Numbers is rotated 180 degrees one by one, we can still get a valid number that is different from X. Each number is required to be rotated.A numbe...原创 2020-04-20 13:57:15 · 160 阅读 · 0 评论 -
Solution for the Square Root of x Using the Go Language
Implement int sqrt(int x) function.Calculate and return the square root of x, where x is a non-negative integer.Since the return type is an integer, the result retains only the integer part, and the...原创 2020-04-19 17:02:13 · 519 阅读 · 0 评论