Leetcode Graph
200. Number of IslandsDescriptionGiven an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. Click to view full description Example 1: Input: grid =...
Leetcode Binary Tree
94. Binary Tree Inorder TraversalDescriptionGiven the root of a binary tree, return the inorder traversal of its nodes’ values. Click to view full description Example 1: Input: root = [1,null,2,3] Output: [1,3,2] Example 2: Input: root = [] Output: [] SolutionIdea: 使用递归的方法,分别计算左子树和右子树的遍历结果,然后合并。 Complexity: Time: O(n), Space: O(n) 1234567891011# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# ...
后端开发问题记录 —— 数据存储方案选择
问题描述在游戏进行过程中,某些数据需要频繁地读取和写入,例如玩家调度信息和历史剧情信息。游戏结束后,这些数据需要被持久化存储,以便后续分析和使用。因此,我们需要选择一个合适的存储方案。 解决方案确定的存储方案为: Redis 作为缓存层,MongoDB 作为持久化存储层。 Redis:高性能内存数据库Redis 是一个基于内存的 NoSQL 数据库,常用于缓存和快速的数据操作。它的主要特点包括: 内存操作:数据存储在内存中,相比 MongoDB 的磁盘存储,读写速度极快,适合高频访问数据。 多种数据结构支持:支持字符串、哈希、列表、集合、有序集合等数据类型。 适合实时需求:非常适用于实时数据的存储和处理,因为其读写速度极快,可以快速响应请求。 MongoDB:文档型数据库MongoDB 是一个基于文档的 NoSQL 数据库,擅长处理复杂的数据结构和大规模的数据存储。其主要特点包括: 灵活的数据模型:以 BSON(类似...
Leetcode Linked List
160. Intersection of Two Linked ListsDescriptionGiven the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null. Click to view full description Example 1: Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3 Output: Intersected at '8' Example 2: Input: intersectVal = 2, listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB =...
前端开发问题记录 —— iOS Safari 浏览器音频播放异常
问题描述在前端开发的过程中,遇到了一个音频播放异常的问题。在游戏结束时,需要播放一段结束音效,在 PC 端开发测试时均为发现异常,但是在 iOS Safari 浏览器中播放时,会出现音频不播放的问题。经过测试发现移动端其他浏览器(如 Chrome、百度等)均正常,因此可以确定是 iOS Safari 浏览器的问题。 解决过程首先在 iPhone 的 设置 -> Safari 浏览器 -> 高级 中,将 “网络检查器” 开启,用数据线连接至 Mac。然后在 Mac 上打开 Safari 浏览器,在 Safari 浏览器中打开 开发者工具,连接手机中 Safari 浏览的网页查看是否有报错。 观察 http 请求并未报错,获取音频文件返回 206 状态码,说明请求是成功的。 之后,参考某 stackoverflow 的回答,尝试给播放器添加 muted 属性,在播放时设置为 false,发现可以播放,但播放的仅为部分音频。 在寻找原因无果后,决定参考另一个没有异常的项目。该项目使用了一个第三方音频播放库...
Leetcode Matrix
73. Set Matrix ZeroesDescriptionGiven an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0s. You must do it in place. Click to view full description Example 1: Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] Output: [[1,0,1],[0,0,0],[1,0,1]] Example 2: Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]] Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]] SolutionApproach 1: 标记数组Idea: 使用两个布尔数组分别记录矩阵的行和列是否需要被置零。 Complexity: Time: O(m * n), Space: O(m +...
《道德经》读书笔记1
前言:为何开始阅读《道德经》最近实习上班以来,一直困扰我的问题是在早晚高峰拥挤的地铁上应该如何打发时间。得益于 🍎 手机的烂信号,刷视频实在不现实,听歌吧地铁的声音又实在太吵,我便思考能不能做些有意义的事,于是我开始尝试读书,重新捡起来已经遗忘很久的阅读习惯。 下载了微信读书,随手翻翻便刷到了 《百年孤独》 这本已经听说了很久的书,开始了我与阅读的重逢。这种感觉既熟悉又陌生,恍惚间仿佛回到了小时候。在那个智能手机还没有普及的年代,在午后慵懒的阳光里,我沉浸在各种故事中,度过一个又一个下午。一转眼已经这么多年过去了,我早已不再保有阅读的习惯。在这个快节奏的时代,我已经被碎片化的信息裹挟,习惯了快速浏览,习惯了快速获取与快速遗忘的循环。再加上我学的计算机专业的获取知识的方式,更是让我彻底遗忘沉浸式阅读为何物。然而这次与阅读重逢,我意外惊喜地发现,我还可以如此轻易地沉浸在阅读的世界,享受其中。通勤路上,我通过阅读仿佛进入了我自己的世界,享受着那来之不易的、与外界隔绝的宁静。通勤的时间仿佛也变得不再那么煎熬,即使是被陌生人的呼吸和地铁的轰鸣声包围。 读了几天 《百年孤独》...
Leetcode Array & String
560. Subarray Sum Equals KDescriptionGiven an array of integers nums and an integer k, return the total number of subarrays whose sum equals k. Click to view full description Example 1: Input: nums = [1,1,1], k = 2 Output: 2 Example 2: Input: nums = [1,2,3], k = 3 Output: 2 SolutionIdea: 使用前缀和,遍历数组,计算当前前缀和与 k 的差值,如果差值在哈希表中,则说明存在一个子数组,其和为 k。 若某个区间 [i, j] 的和为 k,则满足 pre_sum[j] - pre_sum[i - 1] = k,即 pre_sum[j] - k = pre_sum[i - 1]。 Complexity: Time: O(n), Space:...
Leetcode Sliding Window
3. Longest Substring Without Repeating CharactersDescriptionGiven a string s, find the length of the longest substring without repeating characters. Click to view full description Example 1: Input: s = "abcabcbb" Output: 3 Example 2: Input: s = "bbbbb" Output: 1 SolutionIdea: 使用滑动窗口。当窗口内的字符串不包含重复字符时,记录长度,并尝试缩小窗口,即 i 向右移动。缩小到不满足条件时,再尝试扩大窗口,即 j 向右移动。 Complexity: Time: O(n), Space: O(1) 1234567891011121314151617181920class Solution(object): def...
Leetcode Two Pointers
283. Move ZeroesDescriptionGiven an integer array nums, move all 0’s to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. Click to view full description Example 1: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Example 2: Input: nums = [0] Output: [0] SolutionIdea: 使用双指针,一个指针指向当前非零元素的位置,另一个指针遍历整个数组。如果当前元素不为零,则将当前元素赋值给非零指针位置,并递增非零指针。最后将非零指针之后的元素全部赋值为零。 Complexity: Time: O(n), Space:...





