随笔分类 - LeetCode
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Example 2: Input: nums = [1], k = 1 Output: [1] Example 2: Note:
阅读全文
摘要:Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. Example: MovingAverage m = new Movin
阅读全文
摘要:Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Given s = "hello", return "holle". Example 2:Given s
阅读全文
摘要:Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, yo
阅读全文
摘要:Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum pro
阅读全文
摘要:Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example 1: Example 2: Input: 5 Output: false Example 2: Follo
阅读全文
摘要:Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers. You may
阅读全文
摘要:Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity sake, you may assume: words.txt contains only low
阅读全文
摘要:Given a text file file.txt, transpose its content. You may assume that each row has the same number of columns and each field is separated by the ' '
阅读全文
摘要:How would you print just the 10th line of a file? For example, assume that file.txt has the following content: Your script should output the tenth lin
阅读全文
摘要:The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users tabl
阅读全文
摘要:Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. For example, ret
阅读全文
摘要:Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. For example, aft
阅读全文
摘要:The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. The Department table holds all dep
阅读全文
摘要:The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id. The Department table hol
阅读全文
摘要:Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything
阅读全文
摘要:Write a SQL query to find all duplicate emails in a table named Person. For example, your query should return the following for the above table: Note:
阅读全文
摘要:Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list -- whose elements may also be integ
阅读全文
摘要:The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id. Given the Em
阅读全文
摘要:Write a SQL query to find all numbers that appear at least three times consecutively. For example, given the above Logs table, 1 is the only number th
阅读全文