. [Swift] LeetCode1169 query invalid transaction | Invalid Transactions

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤ micro-channel public number: to dare (WeiGanTechnologies)
➤ blog Park address: San-ching Wing Chi ( https://www.cnblogs.com/strengthen/ )
➤GitHub address: https://github.com/strengthen/LeetCode
➤ original address: HTTPS: //www.cnblogs. com / strengthen / p / 11407518.html 
➤ If the address is not a link blog Park Yong Shan Chi, it may be crawling author of the article.
➤ text has been modified update! Click strongly recommended that the original address read! Support authors! Support the original!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

A transaction is possibly invalid if:

  • the amount exceeds $1000, or;
  • if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.

Each transaction string transactions[i] consists of comma separated values representing the name, time (in minutes), amount, and city of the transaction.

Given a list of transactions, return a list of transactions that are possibly invalid.  You may return the answer in any order.

Example 1:

Input: transactions = ["alice,20,800,mtv","alice,50,100,beijing"]
Output: ["alice,20,800,mtv","alice,50,100,beijing"]
Explanation: The first transaction is invalid because the second transaction occurs within a difference of 60 minutes, have the same name and is in a different city. Similarly the second one is invalid too.

Example 2:

Input: transactions = ["alice,20,800,mtv","alice,50,1200,mtv"]
Output: ["alice,50,1200,mtv"]

Example 3:

Input: transactions = ["alice,20,800,mtv","bob,50,1200,mtv"]
Output: ["bob,50,1200,mtv"]

Constraints:

  • transactions.length <= 1000
  • Each transactions[i] takes the form "{name},{time},{amount},{city}"
  • Each {name} and {city} consist of lowercase English letters, and have lengths between 1 and 10.
  • Each {time} consist of digits, and represent an integer between 0 and 1000.
  • Each {amount} consist of digits, and represent an integer between 0 and 2000.

If the following two situations, the transaction may not be valid:

  • Transaction amount over ¥ 1000
  • Or it another deal with another city with the same name separated by no more than 60 minutes (60 minutes containing whole)

Each transaction string  transactions[i] by a number of values separated by commas, these values represent the name of the transaction, the time (in minutes), and the amount of the city.

Give you a list of transactions  transactions, it returns a list of transaction may be invalid. You can return the answers in any order.

Example 1:

Input: transactions = [ "alice, 20,800 , mtv", "alice, 50,100, beijing"] 
Output: [ "alice, 20,800, mtv ", "alice, 50,100, beijing"] 
interpretation: first deal is invalid, because the second deal and it intervals of not more than 60 minutes, and the occurrence of the same name in different cities. Similarly, the second deal is invalid.

Example 2:

Input: transactions = [ "alice, 20,800 , mtv", "alice, 50,1200, mtv"] 
Output: [ "alice, 50,1200, mtv "]

Example 3:

Input: transactions = [ "alice, 20,800 , mtv", "bob, 50,1200, mtv"] 
Output: [ "bob, 50,1200, mtv "]

prompt:

  • transactions.length <= 1000
  • Each transaction  transactions[i] according to  "{name},{time},{amount},{city}" the format of the record
  • Each transaction name  {name} and city  {city} by lowercase letters in length  1 to  10 between
  • Each transaction time  {time} by a number of digits that represents a  0 to  1000 integer
  • Per transaction  {amount} by a number of digits that represents a  0 to  2000 integer

Guess you like

Origin www.cnblogs.com/strengthen/p/11407518.html