← 返回 twosigma 的题目列表Maximum Currency Exchange Rate
类型:online_judge
Given a list of exchange rates rates, where rates[i] = [currency1, currency2, rate] denotes that currency1 can be exchanged for currency2 at a rate of rate. Write a function to determine the maximum exchange rate from currency A to currency B. If no such exchange is possible, return -1.
Input
rates: A list of strings with length 0 <= rates.length <= 200, 3 == rates[i].length
currency1 and currency2 are strings with lengths from 1 to 10, rate is a floating-point number
A, B: Strings from 1 to 10, representing the start and end currencies
Output
The maximum exchange rate from currency A to currency B
Example
Example 1:
Input: rates = [['USD', 'EUR', 0.9], ['EUR', 'JPY', 130], ['USD', 'JPY', 115]], A = 'USD', B = 'JPY' Output: 117
Example 2:
Input: rates = [['USD', 'EUR', 0.9], ['EUR', 'JPY', 130]], A = 'USD', B = 'GBP' Output: -1
Example
Input
rates = [['USD', 'EUR', 0.9], ['EUR', 'JPY', 130], ['USD', 'JPY', 115]]
A = 'USD'
B = 'JPY'