![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
韵影
这个作者很懒,什么都没留下…
展开
-
小美的用户名
小美的用户名小美是美团的前端工程师,为了防止系统被恶意攻击,小美必须要在用户输入用户名之前做一个合法性检查,一个合法的用户名必须满足以下几个要求:用户名的首字符必须是大写或者小写字母。用户名只能包含大小写字母,数字。用户名需要包含至少一个字母和一个数字。如果用户名合法,请输出 “Accept”,反之输出 “Wrong”。格式:输入:输入第一行包含一个正整数 T,表示需要检验的用户名数量。接下来有 T 行,每行一个字符串 s,表示输入的用户名。输出:对于每一个输入的用户名 s,请输出一原创 2022-03-02 23:06:37 · 196 阅读 · 0 评论 -
剑指 Offer 28. 对称的二叉树
请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。例如,二叉树 [1,2,2,3,4,4,3] 是对称的。1/ 2 2/ \ / 3 4 4 3但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:1/ 2 2\ 3 3class Solution {public: bool compare(TreeNode* left, TreeNode* right) { if原创 2022-03-01 21:39:02 · 92 阅读 · 0 评论 -
剑指 Offer 27. 二叉树的镜像
请完成一个函数,输入一个二叉树,该函数输出它的镜像。例如输入: 4/ 2 7/ \ / 1 3 6 9镜像输出: 4/ 7 2/ \ / 9 6 3 1示例 1:输入:root = [4,2,7,1,3,6,9]输出:[4,7,2,9,6,3,1]/** * Definition for a binary tree node. * struct TreeNode { * int val; * Tree原创 2022-03-01 21:11:43 · 248 阅读 · 0 评论 -
剑指 Offer 52. 两个链表的第一个公共节点
输入两个链表,找出它们的第一个公共节点。如下面的两个链表:在节点 c1 开始相交。示例 1:输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3输出:Reference of the node with value = 8输入解释:相交节点的值为 8 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,0,1,8原创 2022-03-01 20:46:10 · 52 阅读 · 0 评论 -
剑指 Offer 25. 合并两个排序的链表
输入两个递增排序的链表,合并这两个链表并使新链表中的节点仍然是递增排序的。示例1:输入:1->2->4, 1->3->4输出:1->1->2->3->4->4限制:0 <= 链表长度 <= 1000class Solution {public: string convert(string s, int numRows) { int n = s.length(), r = numRows;原创 2022-03-01 17:24:59 · 237 阅读 · 0 评论 -
6.Z 字形变换
将一个给定字符串 s 根据给定的行数 numRows ,以从上往下、从左到右进行 Z 字形排列。比如输入字符串为 “PAYPALISHIRING” 行数为 3 时,排列如下:P A H NA P L S I I GY I R之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:“PAHNAPLSIIGYIR”。请你实现这个将字符串进行指定行数变换的函数:string convert(string s, int numRows);示例 1:输入:s = “PAY原创 2022-03-01 16:39:34 · 56 阅读 · 0 评论 -
剑指 Offer 18. 删除链表的节点
剑指 Offer 18. 删除链表的节点给定单向链表的头指针和一个要删除的节点的值,定义一个函数删除该节点。返回删除后的链表的头节点。注意:此题对比原题有改动示例 1:输入: head = [4,5,1,9], val = 5输出: [4,1,9]解释: 给定你链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9.示例 2:输入: head = [4,5,1,9], val = 1输出: [4,5,9]解释: 给定你链表中值为 1 的原创 2022-02-28 14:44:31 · 45 阅读 · 0 评论 -
537. 复数乘法
复数 可以用字符串表示,遵循 “实部+虚部i” 的形式,并满足下述条件:实部 是一个整数,取值范围是 [-100, 100]虚部 也是一个整数,取值范围是 [-100, 100]i2 == -1给你两个字符串表示的复数 num1 和 num2 ,请你遵循复数表示形式,返回表示它们乘积的字符串。示例 1:输入:num1 = “1+1i”, num2 = “1+1i”输出:“0+2i”解释:(1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i ,你需要将它转换为 0+2原创 2022-02-25 16:05:51 · 160 阅读 · 0 评论 -
剑指 Offer 10- II. 青蛙跳台阶问题
写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项(即 F(N))。斐波那契数列的定义如下:F(0) = 0, F(1) = 1F(N) = F(N - 1) + F(N - 2), 其中 N > 1.斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得出。答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。示例 1:输入:n = 2输出:1示例 2:输入:n = 5输出:5提示:原创 2022-02-25 12:04:34 · 119 阅读 · 0 评论 -
【无标题】
产品经理(PM)有很多好的idea,而这些idea需要程序员实现。现在有N个PM,在某个时间会想出一个 idea,每个 idea 有提出时间、所需时间和优先等级。对于一个PM来说,最想实现的idea首先考虑优先等级高的,相同的情况下优先所需时间最小的,还相同的情况下选择最早想出的,没有 PM 会在同一时刻提出两个 idea。同时有M个程序员,每个程序员空闲的时候就会查看每个PM尚未执行并且最想完成的一个idea,然后从中挑选出所需时间最小的一个idea独立实现,如果所需时间相同则选择PM序号最小的。直到完原创 2022-02-25 11:24:18 · 50 阅读 · 0 评论 -
【无标题】
给定一个数组序列, 需要求选出一个区间, 使得该区间是所有区间中经过如下计算的值最大的一个:区间中的最小数 * 区间所有数的和最后程序输出经过计算后的最大值即可,不需要输出具体的区间。如给定序列 [6 2 1]则根据上述公式, 可得到所有可以选定各个区间的计算值:[6] = 6 * 6 = 36;[2] = 2 * 2 = 4;[1] = 1 * 1 = 1;[6,2] = 2 * 8 = 16;[2,1] = 1 * 3 = 3;[6, 2, 1] = 1 * 9 = 9;从上述计算可见原创 2022-02-24 23:00:23 · 56 阅读 · 0 评论 -
【无标题】
1/5[编程题]编程题1时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32M,其他语言64MP为给定的二维平面整数点集。定义 P 中某点x,如果x满足 P 中任意点都不在 x 的右上方区域内(横纵坐标都大于x),则称其为“最大的”。求出所有“最大的”点的集合。(所有点的横坐标和纵坐标都不重复, 坐标轴范围在[0, 1e9) 内)如下图:实心点为满足条件的点的集合。请实现代码找到集合 P 中的所有 ”最大“ 点的集合并输出。输入描述:第一行输入点集的个数 N, 接下来 N 行,每原创 2022-02-24 21:51:20 · 51 阅读 · 0 评论 -
Leecode 172
阶乘后的零给定一个整数 n ,返回 n! 结果中尾随零的数量。提示 n! = n * (n - 1) * (n - 2) * … * 3 * 2 * 1示例 1:输入:n = 3输出:0解释:3! = 6 ,不含尾随 0示例 2:输入:n = 5输出:1解释:5! = 120 ,有一个尾随 0示例 3:输入:n = 0输出:0提示:0 <= n <= 104进阶:你可以设计并实现对数时间复杂度的算法来解决此问题吗?相关标签数学作者:字节校园链接:htt.原创 2022-02-24 15:01:42 · 49 阅读 · 0 评论 -
1. 两数之和
1. 两数之和难度简单11417给定一个整数数组nums和一个整数目标值target,请你在该数组中找出和为目标值target 的那两个整数,并返回它们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。你可以按任意顺序返回答案。示例 1:输入:nums = [2,7,11,15], target = 9输出:[0,1]解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。示例 2:...原创 2021-06-25 22:04:32 · 109 阅读 · 0 评论 -
188. Best Time to Buy and Sell Stock IV
You are givenan integer array prices where prices[i]is the price of a given stock on the ith day.Design an algorithm to find the maximum profit. You may complete at most k transactions.Notice that you may not engage in multiple transactions simultane..原创 2020-11-13 23:28:16 · 101 阅读 · 0 评论 -
123. Best Time to Buy and Sell Stock III
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (i.e., y...原创 2020-11-13 22:31:53 · 84 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You may complete as many transactions as you like, but you need to pay the transa原创 2020-11-13 12:38:02 · 53 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
Say you have an array prices for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times)原创 2020-11-13 11:24:40 · 48 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
题目描述121. Best Time to Buy and Sell Stock难度简单1295Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), d...原创 2020-11-13 10:44:28 · 53 阅读 · 0 评论 -
52. N-Queens II
难度困难205Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return the number ofdistinct solutions to then-queens puzzle.Example:Input: 4Output: 2Explanatio...原创 2020-11-02 22:51:43 · 59 阅读 · 0 评论 -
Leetcode 213House Robber II
213. House Robber II难度中等406You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place arearranged in a circle.That means the first house is the neighbor of the last ..原创 2020-11-01 18:15:37 · 74 阅读 · 0 评论 -
Leetcode 198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses原创 2020-11-01 17:40:32 · 70 阅读 · 0 评论