Author: admin
-
System Design Interview Questions: How would you design a URL shortening service like bit.ly?
•
如何设计一个类似bit.ly的URL缩短服务? What is a URL shortening service? URL缩短服务是什么? English: A URL shortening service takes a long URL and returns a shorter, unique URL that redirects to the original one. Chinese: URL缩短服务接受一个长URL并返回一个更短的、唯一的URL,该URL重定向到原始URL。 Why is it important? 为什么它很重要? English: It simplifies sharing links, especially on platforms with character limits like Twitter. Chinese:…
-
System Design 101: 8 Must-Know Strategies to Scale Your System
•
Scaling your system efficiently is crucial for handling increased load and ensuring high availability and performance. Here are eight essential strategies for scaling your system: 高效地扩展系统对于处理增加的负载和确保高可用性和性能至关重要。以下是扩展系统的八个基本策略: Strategy Description 策略 描述 Stateless Services Design services to not maintain state internally. State is stored externally (e.g., in a database). 无状态服务 设计服务不在内部维护状态。状态存储在外部(例如数据库)。 Horizontal…
-
LeetCode: 121 Best Time to Buy and Sell Stock
•
You are given an array prices where prices[i] is the price of a given stock on the i-th day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit…
-
LeetCode: 136 Single Number
•
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. Example: Input: nums = [2, 2, 1] Output: 1 Example: Input: nums = [4, 1, 2, 1, 2] Output: 4 Example: Input: nums = [1] Output: 1 问题 给定一个非空整数数组 nums,其中每个元素都出现两次,只有一个元素出现一次。找出那个只出现一次的元素。 解决方案 1…
-
LeetCode: 18 4Sum
•
Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: 0 <= a, b, c, d < n a, b, c, and d are distinct. nums[a] + nums[b] + nums[c] + nums[d] == target Example: Input: nums = [1,…
-
LeetCode: 15 3Sum
•
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Example: Input: nums = [-1, 0, 1, 2,…
-
LeetCode: 454 4Sum II
•
Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0. Example: Input: nums1 = [1, 2], nums2 = [-2,-1], nums3 = [-1, 2], nums4 = [0, 2]…
-
LeetCode: 704 Binary Search
•
Given a sorted (in ascending order) integer array nums of n elements and a target value target, write a function to search target in nums. If target exists, then return its index, otherwise, return -1. Example: Input: nums = [-1, 0, 3, 5, 9, 12], target = 9 Output: 4…
-
Python 101: 57 Built-in Functions
•
Python 57 Built-in Functions Python 57 Built-in Functions Built-in Functions 内置函数 A abs() aiter() all() anext() any() ascii() B bin() bool() breakpoint() bytearray() bytes() C callable() chr() classmethod() compile() complex() D delattr() dict() dir() divmod() E enumerate() eval() exec() F filter() float() format() frozenset() G getattr() globals() H hasattr() hash()…
-
Python 101: The Difference Between Two Function Definitions in Python
•
Understanding the differences between two seemingly similar function definitions in Python is crucial for avoiding unintended side effects and understanding Python’s handling of default arguments. Function Definition 1 def f(a, L=None): if L is None: L = [] L.append(a) return L Function Definition 2 def f(a, L=[]): L.append(a) return L…