Home

[leetcode] 1732. Find the Highest Altitude _ Algorithm Problem Solve for python

1. Problem 1732. Find the Highest Altitude There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0. You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i​​​​​​ and i + 1 for all (0 <=...

Read more

[leetcode] 338. Counting Bits _ Algorithm Problem Solve for python

1. Problem 338. Counting Bits Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1’s in the binary representation of i. Example 1: Input: n = 2 Output: [0,1,1] Explanation: 0 --> 0 1 --> 1 2 --> 10 Example 2: Input: n = 5 Output: [0,1,1,2,1,2] Explanation: 0 --&...

Read more

[leetcode] 392. Is Subsequence _ Algorithm Problem Solve for python

1. Problem 392. Is Subsequence Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., “ace” is a subseq...

Read more

[leetcode] 283. Move Zeroes _ Algorithm Problem Solve for python

1. Problem 283. Move Zeroes Given 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. Example 1: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Example 2: Input: nums = [0] Output: [0] Constraints: ...

Read more

[leetcode] 605. Can Place Flowers _ Algorithm Problem Solve for python

1. Problem 605. Can Place Flowers You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0’s and 1’s, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flo...

Read more

[leetcode] 226. Invert Binary Tree _ Algorithm Problem Solve for python

1. Problem 226. Invert Binary Tree Given the root of a binary tree, invert the tree, and return its root. F(0) = 0, F(1) = 1 F(n) = F(n - 1) + F(n - 2), for n > 1. Given n, calculate F(n). Example 1: Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: Input: root = [2,1,3] Output: [2,3,1] Example 3: Input: root = [] Out...

Read more