JinFei's Blog

Thinking will not overcome fear but action will.

[LeetCode]最大可整合子数组的长度

整合子数组

题目描述 先给出可整合数组的定义:如果一个数组在排序之后,每相邻两个数的差的绝对值都为1,或者该数组长度为1,则该数组为可整合数组。例如,[5, 3, 4, 6, 2]排序后为[2, 3, 4, 5, 6],符合每相邻两个数差的绝对值都为1,所以这个数组为可整合数组 给定一个数组arr, 请返回其中最大可整合子数组的长度。例如,[5, 5, 3, 2, 6, 4, 3]的最大可整合子数...

[LeetCode]148. Sort List

链表排序

题目描述 Sort a linked list in O(n log n) time using constant space complexity. Example1: Input: 4->2->1->3 Output: 1->2->3->4 Example2: Input: -1->5->...

[LeetCode]227. Basic Calculator II

四则运算

题目描述 Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer divisio...

[LeetCode]166. Fraction to Recurring Decimal

实现除法

题目描述 Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parent...

[LeetCode]29. Divide Two Integers

不适用乘除做除法

题目描述 Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer d...

[LeetCode]189. Rotate Array

实现旋转数组

题目描述 Given an array, rotate the array to the right by k steps, where k is non-negative. Example1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate...

[LeetCode]28. Implement strStr()

实现自己的substr

题目描述 Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example1: Input: haystack = "hello", needle = "ll" ...

[LeetCode]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 space for another array, you must do thi...

[LeetCode]190. Reverse Bits

翻转位

题目描述 Reverse bits of a given 32 bits unsigned integer. Example1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Explanation: The input binary st...

[LeetCode]179. Largest Number

组成最大的字符串

题目描述 Given a list of non negative integers, arrange them such that they form the largest number. Example1: Input: [10,2] Output: "210" Example2: Input: [3,30,34,5,9] O...