leetcode 454 ii
LeetCode 200. 岛屿数量
``` class Solution { public: bool st[310][310]; int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0}; int m,n; int numIslands(vector>& g) { int res=0; n=g.size(),m=g ......
LeetCode 169. 多数元素
``` class Solution { public: int majorityElement(vector& nums) { int cnt=1; int res=nums[0]; for(int i=1;i<nums.size();i++) { if(nums[i]==res) cnt++; ......
LRU 力扣 146 https://leetcode.cn/problems/lru-cache/
一道经典题目,用双向链表去做能够满足O1的复杂度 核心代码如下 class LRUCache { MyLinkedList myLinkedList; int size; int capacity; HashMap<Integer, MyNode> map; public LRUCache(int ......
[LeetCode] 2024. Maximize the Confusion of an Exam
A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing ......
LeetCode
[剑指offer 05.替换空格](https://leetcode.cn/problems/ti-huan-kong-ge-lcof/) ```cpp class Solution { public: string replaceSpace(string s) { string out; for( ......
1644 题「二叉树的最近公共祖先 II
对于这道题来说,p和q不一定存在于树中,所以你不能遇到一个目标值就直接返回,而应该对二叉树进行完全搜索(遍历每一个节点),如果发现p或q不存在于树中,那么是不存在LCA的。 ......
leetcode649队列操作Dota2
基本操作 入队: queue.push() queue.push_back()//两者效果相同 出队: queue.pop(); queue.pop_back();//都从尾部操作 考虑两个因素:1.每个参议员的决定都由之后的参议员决定 2.决定禁用之后都不能在投票 queue<int>radian ......
51. N 皇后&52. N 皇后 II
按照国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子。 n 皇后问题 研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。 给你一个整数 n ,返回所有不同的 n 皇后问题 的解决方案。 每一种解法包含一个不同的 n 皇后问题 的棋子放置方案,该方 ......
C# IIS发布的API项目中的图片访问404问题
IIS发布的API项目图片无法加载问题,API站点的路由配置不允许直接访问图片资源图片资源的请求被重定向或拦截。 解决方式:新建一个WEB站点,配置开放好端口,上传图片路径指向此站点目录。 访问方式:http:ip:端口/uploads/1.jpg ......
[LeetCode] 2178. Maximum Split of Positive Even Integers
You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers. For example, given finalSum = 12, the fol ......
[LeetCode] 2600. K Items With the Maximum Sum
There is a bag that consists of items, each item has a number 1, 0, or -1 written on it. You are given four non-negative integers numOnes, numZeros, n ......
Leetcode: Algorithm
1. Boyer-Moore Voting Algorithm identify the majority element (frequency > n/2) class Solution { public int majorityElement(int[] nums) { int count = ......
leetcode-1652-easy
Defuse the Bomb ``` You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n ......
leetcode-1629-easy
Slowest Key ``` You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and ......
4.3 Recurrent Neural Network (RNN) II
# 1. RNN 怎么学习 ## 1.1 Loss Function 如果要做learning的话,你要定义一个cost function来evaluate你的model是好还是不好,选一个parameter要让你的loss 最小.那在Recurrent Neural Network里面,你会怎么定 ......
LeetCode 160. 相交链表
``` /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class ......
【笔试实战】LeetCode题单刷题-编程基础 0 到 1【三】
博客推行版本更新,成果积累制度,已经写过的博客还会再次更新,不断地琢磨,高质量高数量都是要追求的,工匠精神是学习必不可少的精神。因此,大家有何建议欢迎在评论区踊跃发言,你们的支持是我最大的动力,你们敢投,我就敢肝 ......
leetcode207 课程表(拓扑排序)
public boolean canFinish(int numCourses, int[][] prerequisites) { //每个点的入度 int[] d = new int[numCourses]; //邻接表定义 ArrayList<ArrayList<Integer>> list = ......
Leetcode155. 最小栈
``` class MinStack { public: stack st; multiset s; MinStack() { } void push(int val) { st.push(val); s.insert(val); } void pop() { int val=st.top(); s ......
图-邻接表-leetcode207
你这个学期必须选修 numCourses 门课程,记为 0 到 numCourses - 1 。 在选修某些课程之前需要一些先修课程。 先修课程按数组 prerequisites 给出,其中 prerequisites[i] = [ai, bi] ,表示如 ......
代码随想录算法训练营第二十四天| 491.递增子序列 46.全排列 47.全排列 II
491.递增子序列 此题的难点: 1,前提需要保留原有顺序 2,保证递增 3,保证去重 注意: 去重一定要有set的同时保证有顺序 代码: 1 void findSubsequences_trackBack(vector<int>& nums, int startIndex, vector<int> ......
[LeetCode] 2679. Sum in a Matrix
You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty: From eac ......
LeetCode/公平分发饼干
给你一个整数数组 cookies ,其中 cookies[i] 表示在第 i 个零食包中的饼干数量。 另给你一个整数 k 表示等待分发零食包的孩子数量,所有 零食包都需要分发。在同一个零食包中的所有饼干都必须分发给同一个孩子,不能分开。 分发的 不公平程度 定义为单个孩子在分发过程中能够获得饼干的最 ......
并行课程II
给你一个整数 n 表示某所大学里课程的数目,编号为 1 到 n ,数组 relations 中, relations[i] = [xi, yi] 表示一个先修课的关系,也就是课程 xi 必须在课程 yi 之前上。同时你还有一个整数 k 。 在一个学期中,你 最多 可以同时上 k 门课,前提是这些课的 ......
算法学习day07哈希表part02-454、383、15、18
package SecondBrush.Hash; import java.util.HashMap; import java.util.Map; /** * 454. 四数相加 II * 给你四个整数数组 nums1、nums2、nums3 和 nums4 ,数组长度都是 n ,请你计算有多少个元 ......
LeetCode 周赛 352(2023/07/02)一场关于子数组的专题周赛
> **本文已收录到 [AndroidFamily](https://github.com/pengxurui/AndroidFamily),技术和职场问题,请关注公众号 [彭旭锐] 和 [BaguTree Pro] 知识星球提问。** - 往期回顾:[LeetCode 单周赛第 350 场 · 滑 ......
LeetCode 538. 把二叉搜索树转换为累加树
#题目链接:[LeetCode 538. 把二叉搜索树转换为累加树](https://leetcode.cn/problems/convert-bst-to-greater-tree/) ##题意: **给出二叉 搜索 树的根节点,该树的节点值各不相同,请你将其转换为累加树(Greater Sum ......
LeetCode 108. 将有序数组转换为二叉搜索树
#题目链接:[LeetCode 108. 将有序数组转换为二叉搜索树](https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/) ##题意: **给你一个整数数组 nums ,其中元素已经按 升序 排列,请你将 ......
LeetCode 669. 修剪二叉搜索树
#题目链接:[LeetCode 669. 修剪二叉搜索树](https://leetcode.cn/problems/trim-a-binary-search-tree/) ##题意: **给你二叉搜索树的根节点 root ,同时给定最小边界low 和最大边界 high。通过修剪二叉搜索树,使得所有 ......
LeetCode 450. 删除二叉搜索树中的节点
#题目链接:[LeetCode 450. 删除二叉搜索树中的节点](https://leetcode.cn/problems/delete-node-in-a-bst/) ##题意: **给定一个二叉搜索树的根节点 root 和一个值 key,删除二叉搜索树中的 key 对应的节点,并保证二叉搜索树 ......