
LeetCode
AgoniAngel
我的bug早已饥渴难耐
展开
-
【专题】链表
21. 合并两个有序链表将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。输入:1->2->4, 1->3->4输出:1->1->2->3->4->423. 合并K个排序链表合并k个排序链表,返回合并后的排序链表。请分析和描述算法的复杂度。输入:[1->4->5,1->3->4,2->6]输出: 1->1-...原创 2020-07-25 11:54:03 · 148 阅读 · 0 评论 -
【专题】回文
一、字符串问题5.最长回文子串【中等】给定一个字符串s,找到s中最长的回文子串。你可以假设s的最大长度为 1000。输入: "babad"输出: "bab"注意: "aba" 也是一个有效答案。214. 最短回文串【困难】给定一个字符串s,你可以通过在字符串前面添加字符将其转换为回文串。找到并返回可以用这种方式转换的最短回文串。输入: "aacecaaa"输出: "aaacecaaa"输入: "cbbd"输出: "bb"516. 最...原创 2020-07-20 20:07:43 · 242 阅读 · 0 评论 -
【专题】在数字中间添加运算符,使等式成立
【招商银行卡笔试 20.04.08】给定一个字符串s和一个整数k,只含有数字0-9,在字符串中随意插入 + 号或 - 号(不能在两端插入),使得算式结果为k。输出可行的方案数。1字符串长度12,11e4类似题:Leetcode494#include <iostream>using namespace std;int k, cnt;string s;vo...原创 2020-04-11 18:46:04 · 3126 阅读 · 0 评论 -
【专题】打家劫舍/粉刷房子/栅栏涂色
打家劫舍【LeetCode 198】【题目】给定一个非负整数数组,代表每个房子的现金数。如果两间相邻的房屋同时被小偷闯入,系统会自动报警。计算小偷在不触动警报装置的情况下,能够偷窃到的最高金额。输入: [2,7,9,3,1]输出: 12解释: 偷窃 1 号房屋 (金额 = 2), 偷窃 3 号房屋 (金额 = 9),接着偷窃 5 号房屋 (金额 = 1)。 偷窃到的最高金额...原创 2020-04-16 21:58:12 · 324 阅读 · 0 评论 -
LeetCode 1246 删除回文子数组
微软笔试题 20.3.25【题目】给你一个整数数组 arr,每一次操作你都可以选择并删除它的一个 回文子数组 arr[i], arr[i+1], ..., arr[j],其中 i <= j。注意,每当你删除掉一个子数组,右侧元素都会自行向前移动填补空位。请你计算并返回从数组中删除所有数字所需的最少操作次数。原创 2020-03-26 14:49:47 · 970 阅读 · 0 评论 -
【专题】编辑距离/最长公共子序列/最长公共子数组
两个字符串a和b,长度相等,并且只有A和T两种字符。通过2种操作把a变成b,求最少操作次数。第1种操作,替换一个字符第2种操作,交换两个字符的位置示例:输入:TAAATTAATTAA输出:3解释:把第1个字符T替换为A,第3、5个字符交换,第4、6个字符交换。来自360笔试(2020.3.24)【思路】这题类似于编辑距离,但操作不同,总体要简单些,不需要...原创 2020-03-24 23:41:10 · 448 阅读 · 0 评论 -
LeetCode 298 二叉树最长连续序列
【题目】给定一个二叉树,求最长连续序列的长度。连续序列是一条父节点到子节点路径,路径上的数连续递增(子节点的数比父节点大1)。Given a binary tree, find the length of the longest consecutive sequence path.The path refers to any sequence of nodes from some ...原创 2020-03-22 11:42:44 · 760 阅读 · 0 评论 -
【专题】寻找缺失/重复/只出现一次的数
LeetCode41. 缺失的第一个正数给定一个未排序的整数数组,找出其中没有出现的最小的正整数。要求时间O(n),空间O(1)。输入: [1,2,0] 输出: 3输入: [3,4,-1,1] 输出: 2输入: [7,8,9,11,12] 输出: 1LeetCode268. 0-n中缺失的一个数字给定一个包含 0,...原创 2020-03-15 15:30:23 · 734 阅读 · 0 评论 -
【专题】最长子串问题(无重复/最多k个不同字符) -滑动窗口
目录1.LeetCode 3:无重复字符的最长子串(Medium)2.LeetCode 159:最多有2个不同字符的最长子串 (Medium)3.LeetCode 340:最多有k个不同字符的最长子串 (Medium)1.LeetCode 3:无重复字符的最长子串(Medium)给定一个字符串,请你找出其中不含有重复字符的最长子串的长度。输入: "abcabcbb...原创 2020-03-08 23:05:20 · 540 阅读 · 0 评论 -
LeetCode 246/247/248 中心对称数
目录LeetCode 246 (Easy):判断一个数是否为中心对称数LeetCode 247 (Medium):给出长度为 n 的所有中心对称数LeetCode 248 (Hard):求给定区间内有多少中心对称数 LeetCode 246 (Easy):判断一个数是否为中心对称数 A strobogrammatic number is a number that looks...原创 2020-03-05 18:08:41 · 1410 阅读 · 0 评论 -
LeetCode 156:上下翻转二叉树
题目Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the or...原创 2019-10-11 21:53:59 · 1093 阅读 · 1 评论 -
LeetCode 305:岛屿数量2
题目A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand operation which turns the water at position (row, col) into a land. Given a list of positions to ope...原创 2019-10-21 23:34:23 · 829 阅读 · 0 评论