AILab Notes

LeetCode Logo

200. 岛屿数量

https://leetcode.cn/problems/number-of-islands/description 给你一个由 ‘1’(陆地)和 ‘0’(水)组成的的二维网格,请你计算网格中岛屿的数量。 岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。 此外,你可以假设该网格的四条边均被水包围。 示例 1: 输入:grid = [   [‘1′,’1′,’1′,’1′,’0’],   [‘1′,’1′,’0′,’1′,’0’],   [‘1′,’1′,’0′,’0′,’0’],   [‘0′,’0′,’0′,’0′,’0’] ] 输出:1 示例 2: 输入:grid = [   [‘1′,’1′,’0′,’0′,’0’],   [‘1′,’1′,’0′,’0′,’0’],   [‘0′,’0′,’1′,’0′,’0’],   [‘0′,’0′,’0′,’1′,’1’] ] 输出:3 提示: 思路:遍历二维数组并用递归方法DFS数组,遇到陆地则DFS设置成海水,避免重复访问陷入死循环 C#实现:

200. 岛屿数量 Read More »

LeetCode Logo

2. 两数相加

https://leetcode.cn/problems/add-two-numbers 给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。 请你将两个数相加,并以相同形式返回一个表示和的链表。 你可以假设除了数字 0 之外,这两个数都不会以 0 开头。 示例 1: 输入:l1 = [2,4,3], l2 = [5,6,4] 输出:[7,0,8] 解释:342 + 465 = 807. 示例 2: 输入:l1 = [0], l2 = [0] 输出:[0] 示例 3: 输入:l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9] 输出:[8,9,9,9,0,0,0,1] 提示: 思路:链表遍历 C#实现

2. 两数相加 Read More »

LeetCode Logo

75. 颜色分类

https://leetcode.cn/problems/sort-colors/description 给定一个包含红色、白色和蓝色、共 n 个元素的数组 nums ,原地 对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。 我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。 必须在不使用库内置的 sort 函数的情况下解决这个问题。 示例 1: 输入:nums = [2,0,2,1,1,0] 输出:[0,0,1,1,2,2] 示例 2: 输入:nums = [2,0,1] 输出:[0,1,2] 提示: 进阶: 思路:用双指针法把数组分成三部分区域,第一部分是红色区域,其右边界是p0;最后一部分是蓝色区域,其左边界是p2;从头到尾遍历数组并进行判断元素属于什么区域,交换元素并更新指针p0或p2 C#实现

75. 颜色分类 Read More »

LeetCode Logo

146. LRU 缓存

https://leetcode.cn/problems/lru-cache/description 请你设计并实现一个满足  LRU (最近最少使用) 缓存 约束的数据结构。 实现 LRUCache 类: 函数 get 和 put 必须以 O(1) 的平均时间复杂度运行。 示例: 输入[“LRUCache”, “put”, “put”, “get”, “put”, “get”, “put”, “get”, “get”, “get”][[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]输出[null, null, null, 1, null, -1, null, -1, 3, 4]解释LRUCache lRUCache = new LRUCache(2);lRUCache.put(1, 1); // 缓存是 {1=1}lRUCache.put(2, 2); // 缓存是 {1=1, 2=2}lRUCache.get(1); // 返回 1lRUCache.put(3,

146. LRU 缓存 Read More »

LeetCode_Sharing

5. 最长回文子串

https://leetcode.cn/problems/longest-palindromic-substring 给你一个字符串 s,找到 s 中最长的 回文 子串。 示例 1: 输入:s = “babad” 输出:”bab” 解释:”aba” 同样是符合题意的答案。 示例 2: 输入:s = “cbbd” 输出:”bb” 提示: 思路:利用动态规划,如果 s[i] == s[j],并且中间的子串 s[i+1..j-1] 也是回文,那么 s[i..j] 也是回文, 详细逻辑见实现 C#实现

5. 最长回文子串 Read More »

LeetCode_Sharing

1. 两数之和

https://leetcode.cn/problems/two-sum/description 简单 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target  的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案,并且你不能使用两次相同的元素。 你可以按任意顺序返回答案。 示例 1: 输入:nums = [2,7,11,15], target = 9 输出:[0,1] 解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。 示例 2: 输入:nums = [3,2,4], target = 6 输出:[1,2] 示例 3: 输入:nums = [3,3], target = 6 输出:[0,1] 提示: 进阶:你可以想出一个时间复杂度小于 O(n2) 的算法吗? 思路: C#代码实现

1. 两数之和 Read More »

cyber security, hacker, security, internet, protection, secure, padlock, firewall, protect, password, safety, lock, technology, computer, network, access, privacy, gray computer, gray technology, gray laptop, gray network, gray internet, gray security, gray safety, cybersecurity, cyber security, cyber security, cybersecurity, cybersecurity, cybersecurity, cybersecurity, cybersecurity

Question: What are the risks of pseudo-random number attacks in smart contracts, and how can they be mitigated?

When pseudo-random numbers are used for critical decisions in smart contracts, their predictability can create security vulnerabilities. Such attacks typically occur in two main ways: Security Measures Against Pseudo-Random Number Attacks

Question: What are the risks of pseudo-random number attacks in smart contracts, and how can they be mitigated? Read More »

cyber security, hacker, security, internet, protection, secure, padlock, firewall, protect, password, safety, lock, technology, computer, network, access, privacy, gray computer, gray technology, gray laptop, gray network, gray internet, gray security, gray safety, cybersecurity, cyber security, cyber security, cybersecurity, cybersecurity, cybersecurity, cybersecurity, cybersecurity

Question: How do time-dependent attacks in smart contracts work, and how can they be prevented?

A time-dependent attack in smart contracts happens when attackers manipulate the contract’s clock or time-related functions to trigger specific conditions, allowing them to gain unauthorized assets or unfair advantages. These attacks exploit the fact that many contracts rely on timestamps or intervals to decide when certain actions should occur. In this article, we’ll look at

Question: How do time-dependent attacks in smart contracts work, and how can they be prevented? Read More »

A detailed macro shot of a brass padlock with a key on heavy steel chains, symbolizing security and protection.

Question: What is a reentrancy attack in smart contracts, and how can it be detected and prevented?

A reentrancy attack is one of the most common security issues in smart contracts. It usually occurs when a contract calls an external contract’s function (such as a custom payment handler) right after sending Ether. If the attacker exploits this feature, they can repeatedly call the original contract’s function from within the external call. This

Question: What is a reentrancy attack in smart contracts, and how can it be detected and prevented? Read More »