大道至简

人生苦短,我用Python.

LeetCode-单词拆分

记忆化递归

1、单词拆分(139) 给定一个非空字符串s 和一个包含非空单词的列表 wordDict,判定 s是否可以被空格拆分为一个或多个在字典中出现的单词。 说明: 拆分时可以重复使用字典中的单词。 你可以假设字典中没有重复的单词。 示例 1: 输入: s = "leetcode", wordDict = ["leet", "code"] 输出: true 解释: 返回 tru...

不使用基本运算符实现两个数加法

不使用基本运算符实现两个数加法

1、题目 写一个函数,求两个整数之和,要求在函数体内不得使用 “+”、“-”、“*”、“/” 四则运算符号。   示例: 输入: a = 1, b = 1 输出: 2   提示: a, b 均可能是负数或 0 结果不会溢出 32 位整数 2、思路 对于计算两个十进制数加法时如13+9,我们可以先计算不进位下的和,所谓不进位就是不考虑进位对结果造成的影响, 13+9在...

LeetCode-1053. Previous Permutation With One Swap

LeetCode-1053. Previous Permutation With One Swap

1、题目 Given an array A of positive integers (not necessarily distinct), return the lexicographically largest permutation that is smaller than A, that can be made with one swap (A swap exchanges the...

LeetCode-969. Pancake Sorting

LeetCode-969. Pancake Sorting

1、题目 Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, then reverse the order of the first k elements of A. We want to perform zero or more pancak...

LeetCode-1035. Uncrossed Lines

LeetCode-1035. Uncrossed Lines

1、题目 We write the integers of A and B (in the order they are given) on two separate horizontal lines. Now, we may draw connecting lines: a straight line connecting two numbers A[i] and B[j] such ...

LeetCode-Array中几种连续子序列问题总结

LeetCode-Array中几种连续子序列问题总结

1 和能被K整除的子数组个数 1.1 题目 Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K. Example 1: Input: A = [4,5,0,-2,-3,1], K = 5 Output: 7 ...

LeetCode-974. Subarray Sums Divisible by K

LeetCode-974. Subarray Sums Divisible by K

1、题目 Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K. Example 1: Input: A = [4,5,0,-2,-3,1], K = 5 Output: 7 Explanation: Ther...

LeetCode-109. Convert Sorted List to Binary Search Tree

LeetCode-109. Convert Sorted List to Binary Search Tree

1、题目 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in w...

LeetCode-142. Linked List Cycle II

LeetCode-142. Linked List Cycle II

1、题目 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent a cycle in the given linked list, we use an integer pos which represents the posi...

LeetCode-148. Sort List

LeetCode-148. Sort List

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

< script src = " / js / bootstrap.min.js " >