- 博客(14)
- 收藏
- 关注
原创 leetcode: 77 Combinations
Combinations 组合 Given two integers n and k, return all possible combinations of k numbers out of 1 … n. You may return the answer in any order. 给定两个整数n和k,返回1,…,n中所有可能的k个数的组合。 backtracking 的方法 递归 class Solution: def combine(self, n: int, k: int) ->
2021-02-10 11:10:34
150
1
原创 leetcode 57: Insert Interval
Insert Interval Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. 给出一个无重叠的,按照区间起始端点排序的区间列表。 在列表中插入一个新的区间,你需要确保列表中
2021-02-09 11:10:51
199
原创 56 Merge Intervals
Merge intervals 合并区间 Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. 合并所有的overlapping intervals, 并且返回一个array 来
2021-02-08 12:37:28
181
原创 leetcode 46: Maximum subarray
Maximum subarray 最大子序和 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Follow up: If you have figured out the O(n) solution, try coding another solution using the div
2021-02-05 14:44:02
141
原创 leetcode 46: Permutations
Permutations 全排列 Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. class Solution: def permute(self, nums: List[int]) -> List[List[int]]: if len(nums)==1: re
2021-02-04 14:52:57
124
原创 leetcode 49. Group Anagrams
Group Anagrams 字母异位词分组 Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original let
2021-02-03 13:42:03
285
原创 leetcode 35. search insert position
search insert position Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. 如果找到这个value,则返回index,如果没有找到,返回按照顺序被插入的index. 常规法 第一种 一个麻
2021-02-02 14:32:23
218
原创 leetcode 27. Remove element
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 array, you must do this by modifying the input array in-place with O(1) extra memory. The ord
2021-02-01 11:03:52
114
原创 leetcode 24. Swap nodes in Pairs
Swap nodes in pairs Given a linked list, swap every two adjacent nodes and return its head. 给定一个链表,交换链表中相邻的结点,并返回其头部。也就是返回交换后的链表 不能只是单纯的改变节点内部的值,而是要实际的进行节点交换。 ...
2021-01-31 11:04:49
160
1
原创 leetcode 22 Generate Parentheses
生成括号 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. 采用回溯法 (1)有许多问题,当要找出它的解集或者要求回答什么解是满足某些约束条件的最佳解时,往往要用回溯法。 (2)基本做法是:搜索,或是一种组织的井井有条的,能避免不必要搜索的穷举式搜索法。这种方法适合于解一些组合数相当大的问题。 (3)回溯法在问题的解空间树中,按深度优先策略,从根结点
2021-01-30 12:42:36
141
原创 leetcode 21.Merge two sorted lists
Merge two sorted listed Merge two sorted linked lists and return is as a sorted list. The list should be made by splicing together the nodes of the first two lists. ’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. (相同类型) Open bracket
2021-01-28 16:11:11
116
原创 leetcode 2. Add two numbers
Add two numbers 题目: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may a
2021-01-27 17:05:44
90
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅