随笔分类 - LeetCode练习
摘要:排列组合类的问题,可以使用经典递归方法和分段迭代法 描述 Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not cont
阅读全文
摘要:在一些求字串含有固定字符最短串,含有不同字符最长子串等问题中,利用 vector<int> map(128, 0)可以解决 题一:最短给定子串 Minimum Window Substring Minimum Window Substring Minimum Window Substring Min
阅读全文
摘要:之前转载过一篇STL的sort方法底层详解的博客:https://www.cnblogs.com/ygh1229/articles/9806398.html 但是我们在开发中会根据自己特定的应用,有新的排序需求,比如下面这道题,当只有0,1,2这三个数字时的排序,我们就可以自己写定制版的排序算法 描
阅读全文
摘要:前言 这里总结了两道表格移动的问题,分别是:Unique Paths 和 题一:Unique Paths 描述 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below
阅读全文
摘要:描述 Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2. You have the following 3 operations perm
阅读全文
摘要:描述: Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example:
阅读全文
摘要:描述 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, wh
阅读全文
摘要:描述 Given a collection of distinct integers, return all possible permutations. Example: 思路一:递归 利用STL的函数swap()来交换数组的元素 思路二 next_permutation方法 利用STL的库函数:
阅读全文
摘要:描述 Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where t
阅读全文
摘要:描述: Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime
阅读全文
摘要:描述 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: 思路 借鉴Merge Two Sorted Lists的解决思路,对两个数组先
阅读全文
摘要:描述 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is
阅读全文
摘要:题目描述: Given a linked list, remove the n-th node from the end of list and return its head. Example: Note: Given n will always be valid. Follow up: Coul
阅读全文
摘要:相关概念: 一棵二叉搜索树(BST)是以一棵二叉树来组织的,可以用链表数据结构来表示,其中,每一个结点就是一个对象,一般地,包含数据内容key和指向孩子(也可能是父母)的指针属性。如果某个孩子结点不存在,其指针属性值为空(NIL)。二叉搜索树中的关键字key的存储方式总是满足二叉搜索树的性质:设x是
阅读全文
摘要:描述: (1)翻转一个链表 (1)翻转一个链表 (1)翻转一个链表 样例 给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null **********************************************************************
阅读全文
摘要:一、最大深度问题 描述: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to t
阅读全文
摘要:描述: 前序遍历: Given a binary tree, return the preorder traversal of its nodes' values. 给出一棵二叉树,返回其节点值的前序遍历。 给出一棵二叉树,返回其节点值的前序遍历。 给出一棵二叉树,返回其节点值的前序遍历。 样例 给
阅读全文