brucesong2020@gmail.com

LeetCode Logo

42. 接雨水

https://leetcode.cn/problems/trapping-rain-water/description 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 示例 1: 输入:height = [0,1,0,2,1,0,1,3,2,1,2,1] 输出:6 解释:上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。 示例 2: 输入:height = [4,2,0,3,2,5] 输出:9 提示: 思路:双指针左右夹逼,动态维护左右最高柱,谁低谁动,水量公式=谁低的最高柱-当前柱高 C#实现:

42. 接雨水 Read More »

LeetCode Logo

3. 无重复字符的最长子串

https://leetcode.cn/problems/longest-substring-without-repeating-characters/description 给定一个字符串 s ,请你找出其中不含有重复字符的 最长 子串 的长度。 示例 1: 输入: s = “abcabcbb” 输出: 3 解释: 因为无重复字符的最长子串是 “abc”,所以其长度为 3。注意 “bca” 和 “cab” 也是正确答案。 示例 2: 输入: s = “bbbbb” 输出: 1 解释: 因为无重复字符的最长子串是 “b”,所以其长度为 1。 示例 3: 输入: s = “pwwkew” 输出: 3 解释: 因为无重复字符的最长子串是 “wke”,所以其长度为 3。   请注意,你的答案必须是 子串 的长度,”pwke” 是一个子序列,不是子串。 提示: 思路:滑动窗口+双指针,右指针不断向前扩充,当遇到重复字符时,不断从左边缩小窗口,直到重复字符消失 C#实现

3. 无重复字符的最长子串 Read More »

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 »