leetcode binary add 67
使用golang解决LeetCode热题Hot100(1-10)
# 使用golang解决LeetCode热题Hot100 ## 1.两数之和 ### https://leetcode.cn/problems/two-sum/ #### 题目 给定一个整数数组 `nums` 和一个整数目标值 `target`,请你在该数组中找出 **和为目标值** *`targe ......
ajax 跨域 如果在head里面加了参数需要在 nginx add_header 里面添加
server { listen 80; server_name yourdomain.com; location / { # 允许跨域请求 add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-M ......
Leetcode刷题记录本
# Leetcode刷题记录本 ### ID: 1 点击查看代码 1. 暴力破解法 ```python class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: in ......
leetcode:下一个排列
class Solution { public: void nextPermutation(vector<int>& nums) { int n=nums.size(); int i=n-2; while(i>=0 && nums[i]>=nums[i+1]){//从后向前,找到第一个降序的,一直升 ......
LeetCode -- 127. 单词接龙
方法一:双向广搜 class Solution { public: int ladderLength(string beginWord, string endWord, vector<string>& wordList) { set<string> se; for(auto it : wordLis ......
LeetCode 热题 100 之 240. 搜索二维矩阵 II
# 题目 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target 。该矩阵具有以下特性: 每行的元素从左到右升序排列。 每列的元素从上到下升序排列。 **示例一** ![image](https://img2023.cnblogs.com/blog/2204134/2 ......
LeetCode 16. 3Sum Closest 双指针+排序
Given an integer array `nums` of length n and an integer `target`, find three integers in nums such that the sum is closest to `target`. Return the su ......
LeetCode从算法到算命—344.翻转字符串
# 344.翻转字符串 ## 题目信息 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 `s` 的形式给出。 不要给另外的数组分配额外的空间,你必须**[原地](https://baike.baidu.com/item/原地算法)修改输入数组**、使用 O(1) 的额外空间解决这 ......
LeetCode 周赛上分之旅 #38 结合排序不等式的动态规划
> ⭐️ **本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 \[彭旭锐] 和 [BaguTree Pro](https://www.mdnice.com/writing/85b28c4e60354865a423728e668fc570) 知识星球提问。** > > 学习数据 ......
LeetCode 周赛上分之旅 # 37 多源 BFS 与连通性问题
> ⭐️ **本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 \[彭旭锐] 和 [BaguTree Pro](https://files.mdnice.com/user/3257/de950859-eb71-4821-a36b-bebe5cff500d.png) 知识星球提问 ......
LeetCode从算法到算命—24.两两交换链表中的节点(0806)
# 24.两两交换链表中的节点 ## 题目信息 给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交换)。 **示例 1:** ![image](https://img2023.cnblogs.com/blog/3083774 ......
leetcode:括号生成
回溯的本质是穷举,穷举所有情况,这里有剪枝,只在有效情况下继续 class Solution { vector<string> res; string str; void backtracking(int left,int right){ if(left<0 || left>right) retur ......
Leetcode第357场周赛
https://leetcode.cn/contest/weekly-contest-357/ ## C 寻找不安全路径 以所有小偷点为源点,跑多源点BFS,求出每个点到最近小偷点的曼哈顿距离,记为w[i, j] 二分答案Mid,只允许走w[i, j] >= mid的点,从源店跑DFS/BFS,看是 ......
Exercise: Equivalent Binary Trees
这个Exercise的答案比较开放,不过遵循说明里面的基本要求: Walk遍历随机创建的有序2叉树,将值写入一个chan,按从小到大的顺序输出10个结果。需要注意的是,这个Exercise的随机2叉树说明里面明确了是tree.New(k)创建k, 2k, ..., 10k。所以输出的时候直接循环读1 ......
【LeetCode剑指offer#06】实现pow函数、计算x的平方根
### 实现pow函数 实现 [pow(*x*, *n*)](https://www.cplusplus.com/reference/valarray/pow/) ,即计算 `x` 的整数 `n` 次幂函数(即,`xn` )。 **示例 1:** ``` 输入:x = 2.00000, n = 10 ......
[LeetCode] 1351. Count Negative Numbers in a Sorted Matrix 统计有序矩阵中的负数
Given a `m x n` matrix `grid` which is sorted in non-increasing order both row-wise and column-wise, return *the number of **negative** numbers in* `g ......
LeetCode从算法到算命—每日一题(0805)
# 21. 合并两个有序链表 ## 题目信息 将两个升序链表合并为一个新的 **升序** 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 **示例 1:** ``` 输入:l1 = [1,2,4], l2 = [1,3,4] 输出:[1,1,2,3,4,4] ``` **示例 2:** ......
LeetCode 206 反转链表,LeetCode 92反转链表Ⅱ
206. 反转链表 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 示例 1: 输入:head = [1,2,3,4,5] 输出:[5,4,3,2,1] 示例 2: 输入:head = [1,2] 输出:[2,1] 示例 3: 输入:head = [] 输出:[] 提示: 链表中 ......
LeetCode -- 722. 删除注释
利用双指针来进行删除操作 class Solution { public: vector<string> removeComments(vector<string>& source) { string str; for(auto it : source) str += it + "'"; int n ......
LeetCode 3. 无重复字符的最长子串
``` class Solution { public: int res=0; int lengthOfLongestSubstring(string s) { int n=s.size (); if(!n) return 0; bool st[128]={false}; for(int j=0,i ......
LeetCode从算法到算命—每日一题(0804)
# 980.不同路径III ## 题目信息 在二维网格 `grid` 上,有 4 种类型的方格: - `1` 表示起始方格。且只有一个起始方格。 - `2` 表示结束方格,且只有一个结束方格。 - `0` 表示我们可以走过的空方格。 - `-1` 表示我们无法跨越的障碍。 返回在四个方向(上、下、左 ......
LeetCode 739. 每日温度
``` class Solution { public: vector dailyTemperatures(vector& t) { stack st; int n=t.size(); vector res(n); for(int i=n-1;i>=0;i--) { while(st.size()& ......
LeetCode -- 980. 不同路径 III
本题让我们求不相交路径数目 方法1:递归/回溯 dfs(x, y, left) 表示从点x, y出发,还剩下left个可行走点的路径数目。 每行走到一个新的点就将该点设置为-1, 避免重复搜索。 当走到终点时,如果left == 0 则答案 + 1 class Solution { int dfs( ......
[LeetCode] 980. Unique Paths III
You are given an m x n integer array grid where grid[i][j] could be: 1 representing the starting square. There is exactly one starting square. 2 repre ......
代码随想录算法训练营第八天| LeetCode 344.反转字符串 541. 反转字符串II 151.翻转字符串里的单词
344.反转字符串 卡哥建议: 本题是字符串基础题目,就是考察 reverse 函数的实现,同时也明确一下 平时刷题什么时候用 库函数,什么时候 不用库函数 题目链接/文章讲解/视频讲解:https://programmercarl.com/0344.%E5%8F%8D%E8%BD%AC%E5%AD ......
LeetCode 热题 100 之 48. 旋转图像
# 题目 给定一个 n × n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。 你必须在 原地 旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像。 ![image](https://img2023.cnblogs.com/blog/22041 ......
How to add link parameter to asp tag helpers in ASP.NET Core MVC
How to add link parameter to asp tag helpers in ASP.NET Core MVC 问题 I have a lot of experience with ASP.NET MVC 1-5. Now I learn ASP.NET Core MVC and ......
LeetCode 热题 100 之 54. 螺旋矩阵
# 题目 给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。 **示例 1:** ![image](https://img2023.cnblogs.com/blog/2204134/202308/2204134-20230803145822194-967 ......
leetcode647. 回文子串
``` class Solution { public: int res=0; int countSubstrings(string s) { int n=s.size(); for(int i=0;i=0&&r=0&&r<n&&s[l]==s[r]) l--,r++,res++; } return ......