雙指針

雙指針題型的解題教學,5 題。有序或可排序的資料,兩端往中間夾通常比巢狀迴圈快一個量級。

Container With Most Water 解題教學示意圖|LeetCode 11

Container With Most Water 解題教學:3 種解法完整比較|LeetCode 11 Best Practice

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).

Find two lines that together with the x-axis form a container, such that the container contains the most water.

Return the maximum amount of water a container can store.

Notice that you may not slant the container.

Container With Most Water 解題教學:3 種解法完整比較|LeetCode 11 Best Practice Read More »

Leetcode, 技術文章, , ,
3Sum Smaller 解題教學示意圖|LeetCode 259

3Sum Smaller 解題教學:3 種解法完整比較|LeetCode 259 Best Practice

Given an array of n integers nums and an integer target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.

3Sum Smaller 解題教學:3 種解法完整比較|LeetCode 259 Best Practice Read More »

Leetcode, 技術文章, , ,
3Sum Closest 解題教學示意圖|LeetCode 16

3Sum Closest 解題教學:3 種解法完整比較|LeetCode 16 Best Practice

Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.

Return the sum of the three integers.

You may assume that each input would have exactly one solution.

3Sum Closest 解題教學:3 種解法完整比較|LeetCode 16 Best Practice Read More »

Leetcode, 技術文章, , ,
3Sum 解題教學示意圖|LeetCode 15

3Sum 解題教學:3 種解法完整比較|LeetCode 15 Best Practice

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

3Sum 解題教學:3 種解法完整比較|LeetCode 15 Best Practice Read More »

Leetcode, 技術文章, , ,
Two Sum 解題教學示意圖|LeetCode 3

Two Sum 解題教學:3 種解法完整比較|LeetCode 1 Best Practice

[LeetCode] 1. Two Sum. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

Two Sum 解題教學:3 種解法完整比較|LeetCode 1 Best Practice Read More »

Leetcode, 技術文章, , ,