標籤為 “problem” 的頁面如下
Posts
1690. Stone Game VII
Leetcode 1690. Stone Game VII 題目 Alice and Bob take turns playing a game, with Alice starting first. There are n stones arranged in a row. On each player’s turn, they can remove either the leftmost stone or the rightmost stone from the row and receive points equal to the sum of the remaining stones' values in the row. The winner is the one with the higher score when
Posts
729. My Calendar I
Leetcode 729. My Calendar I 題目 Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking. Your class will have the method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end. A double booking happens
Posts
1696. Jump Game VI
Leetcode 1696. Jump Game VI 題目 You are given a 0-indexed integer array nums and an integer k. You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive. You
Posts
105. Construct Binary Tree from Preorder and Inorder Traversal
Leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal 題目 Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree. 想法 用前序遍歷及中序遍歷的結果反推二元樹的結構。 前
Posts
746. Min Cost Climbing Stairs
Leetcode 746. Min Cost Climbing Stairs 題目 You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the step with index 0, or the step with index 1. Return the minimum cost to reach the top of the floor. 想法 這個
Posts
128. Longest Consecutive Sequence
Leetcode 128. Longest Consecutive Sequence 題目 Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. 想法 這題是要從一堆沒有規則並且可能會重複數字中,找最長的連續數字串的長度。
Posts
1383. Maximum Performance of a Team
Leetcode 1383. Maximum Performance of a Team 題目 You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the ith engineer respectively. Choose at most k different engineers out of the n engineers to form a team with the maximum performance. The
Posts
752. Open the Lock
Leetcode 752. Open the Lock 題目 You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’. The wheels can rotate freely and wrap around: for example we can turn ‘9’ to be ‘0’, or ‘0’ to be ‘9’. Each move consists of turning one wheel one slot. The lock initially starts at
Posts
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
Leetcode 1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts 題目 You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where: horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, and verticalCuts[j] is the distance from the left of the rectangular cake to the jth vertical
Posts
97. Interleaving String
Leetcode 97. Interleaving String 題目 Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2. An interleaving of two strings s and t is a configuration where they are divided into non-empty substrings such that: s = s1 + s2 + … + sn t = t1 + t2 + … + tm |n - m| <= 1 The interleaving is
Posts
695. Max Area of Island
Leetcode 695. Max Area of Island 題目 You are given an m x n binary matrix grid. An island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. The area of an island is the number of cells with a value 1 in the island. Return the maximum area of an island in