LeetCode: 436. Find Right Interval
public class Solution { public int[] findRightInterval(Interval[] intervals) { NavigableMap<Integer, Integer> map = new TreeMap<>(); int[] result = new int[intervals.length]; for(int i = 0; i < intervals.length; i++) { map.put(intervals[i].start, i); } for (int i = 0; i < intervals.length; ++i) { Map.Entry<Integer, Integer> entry = map.ceilingEntry(intervals[i].end); result[i] = (entry != null) ? entry.getValue() : -1; } return result; } }
相關推薦
python leetcode 436. Find Right Interval
一道很巧妙的題 假設第i個有右區間 那麼intervals[i].end<intervals[i+1].start 因為start唯一 所以我們建立一個列表裡面存的是(intervals[i].start,i) 再利用二分查詢尋找end位於列表中的哪個位置 擴充套件:假設end唯一 尋
LeetCode: 436. Find Right Interval
public class Solution { public int[] findRightInterval(Interval[] intervals) { NavigableMap<Integer, Integer> map = new T
[Leetcode] Binary search--436. Find Right Interval
leetcode top bsp origin simple arch log sea blog Given a set of intervals, for each of the interval i, check if there exists an interv
436. Find Right Interval
Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to t
[LeetCode] Find Right Interval 找右區間
Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of t
Leetcode 366. Find Leaves of Binary Tree
oot mov end res removing self. elf 一個 emp Given a binary tree, collect a tree‘s nodes as if you were doing this: Collect and remove all l
[leetcode-442-Find All Duplicates in an Array]
solution i++ it is runtime span col target ted other Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear t
[leetcode-515-Find Largest Value in Each Tree Row]
ron 遍歷 vector div spa cto int ges pop You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3
[leetcode-438-Find All Anagrams in a String]
not plan english urn tco bst ice style ons Given a string s and a non-empty string p, find all the start indices of p‘s anagrams in s.Str
[LeetCode] 448.Find All Numbers Disappeared in an Array
return htm put lis inpu pear rand ati n) p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4e9072 } p.p2 { margin: 0.0
LeetCode 153 Find Minimum in Rotated Sorted Array
== pad assume mat rac wid san orm trac Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5
LeetCode 162. Find Peak Element 20170706
都是 etc input log com element dex 不能 解題思路 A peak element is an element that is greater than its neighbors. Given an input array where num[
LeetCode 501. Find Mode in Binary Search Tree (找到二叉搜索樹的眾數)
btn https 標簽 one con pac 發現 log 個數字 Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred
[leetcode-652-Find Duplicate Subtrees]
ive 思路 uno tar cat with spa DDU cond Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne
【LeetCode】Find Minimum in Rotated Sorted Array 解題報告
consola simple tom adding eve easy java show post 今天看到LeetCode OJ題目下方多了“Show Tags”功能。我覺著挺好,方便剛開始學習的人分類練習。同一時候也是解題時的思路提示。 【題目】 S
leetcode--515. Find Largest Value in Each Tree Row
largest input http code poll() pro tps pub curl 1、問題描述 You need to find the largest value in each row of a binary tree. Example: Input:
LeetCode 287. Find the Duplicate Number (找到重復的數字)
ant pre ast web integer lan algorithm xtra 理論 Given an array nums containing n + 1 integers where each integer is between 1 and n (inclus
LeetCode 442. Find All Duplicates in an Array (在數組中找到所有的重復項)
nts ext leet 日期 lin dot 目標 input output Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and oth
Leetcode 366: Find Leaves of Binary Tree
clas add left hashset while spa his contains col Given a binary tree, collect a tree‘s nodes as if you were doing this: Collect and remov
Leetcode 609: Find Duplicate File in System
ont sam pri strings question each com pair including Given a list of directory info including directory path, and all the files with cont