Author: admin

  • LeetCode: 2 Add Two Numbers

    You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading…

  • LeetCode: 543 Diameter of Binary Tree

    Given the root of a binary tree, the diameter of the tree is the length of the longest path between any two nodes in the tree. This path may or may not pass through the root. The length of a path between two nodes is represented by the number of…

  • LeetCode: 88 Merge Sorted Array

    You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2, respectively. You need to merge nums2 into nums1 as one sorted array. The final sorted array should not be returned by the…

  • LeetCode: 198 House Robber

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, and the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected, and it will automatically contact the police if two adjacent…

  • LeetCode: 146 LRU Cache

    Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class: LRUCache(int capacity) initializes the LRU cache with positive size capacity. int get(int key) returns the value of the key if the key exists in the cache, otherwise returns -1. void put(int…

  • LeetCode: 509 Fibonacci Number

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is: F(0) = 0, F(1) = 1 F(n) = F(n – 1) + F(n – 2), for n >…

  • LeetCode: 408 Valid Word Abbreviation

    Given a non-empty string word and an abbreviation abbr, return whether the string matches the given abbreviation. A string abbr is a valid abbreviation of word if: It can contain numbers representing how many characters to skip. The numbers should not contain leading zeros. Example: Input: word = "internationalization", abbr…

  • LeetCode: 70 Climbing Stairs

    You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example: Input: n = 3 Output: 3 Explanation: There are three ways to climb to the…

  • Algorithms 101: Deep Dive into the Fibonacci Sequence

    Deep Dive into the Fibonacci Sequence Introduction The Fibonacci sequence is one of the most famous mathematical sequences, often used in algorithms, data structures, and problem-solving. It starts with 0 and 1, and each subsequent number is the sum of the two preceding numbers. Fibonacci numbers have various applications in…

  • Python 101: Understanding SOLID Principles in Python

    Understanding SOLID Principles in Python 理解 SOLID 原则 Introduction SOLID is an acronym that represents five fundamental principles of object-oriented programming (OOP). These principles were introduced by Robert C. Martin and are widely used to design software that is scalable, maintainable, and easier to understand. The SOLID principles help developers…