-
LeetCode: 1299 Replace Elements with Greatest Element on Right Side
•
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array. Example Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Explanation: – Index 0 → The greatest element to the…
-
LeetCode: 234 Palindrome Linked List
•
Given the head of a singly linked list, return true if it is a palindrome. Example Input: head = [1,2,2,1] Output: true Input: head = [1,2] Output: false 问题 给定单链表的头节点 head,如果它是回文链表,则返回 true。 例子 输入: head = [1,2,2,1] 输出: true 输入: head = [1,2] 输出: false Solution Approach: Two Pointers (Fast…
-
Leetcode SQL: 1661. Average Time of Process per Machine
•
1661. Average Time of Process per Machine SQL Code: SELECT machine_id, ROUND(AVG(end_time – start_time), 3) AS processing_time FROM ( SELECT machine_id, process_id, MAX(CASE WHEN activity_type = 'end' THEN timestamp END) AS end_time, MAX(CASE WHEN activity_type = 'start' THEN timestamp END) AS start_time FROM Activity GROUP BY machine_id, process_id ) AS…
-
Leetcode SQL: 1581. Customer Who Visited but Did Not Make Any Transactions
•
1581. Customer Who Visited but Did Not Make Any Transactions SQL Code: SELECT customer_id, COUNT(*) FROM Visits v WITH (NOLOCK) LEFT JOIN Transactions t WITH (NOLOCK) ON v.visit_id = t.visit_id WHERE t.transaction_id IS NULL GROUP BY customer_id; Explanation: *SELECT customer_id, COUNT()**: This line specifies that we want to retrieve the…
-
Leetcode SQL: 378. Replace Employee ID With The Unique Identifier
•
378. Replace Employee ID With The Unique Identifier SQL Code: SELECT eu.unique_id, [name] FROM Employees e WITH (NOLOCK) LEFT OUTER JOIN EmployeeUNI eu WITH (NOLOCK) ON e.id = eu.id; Explanation: SELECT eu.unique_id, [name]: This line specifies that we want to retrieve the unique_id from the EmployeeUNI table and the name…
-
Leetcode SQL: 1683. Invalid Tweets
•
1683. Invalid Tweets SQL Code: SELECT tweet_id FROM Tweets WITH (NOLOCK) WHERE LEN(content) > 15; Explanation: SELECT tweet_id: This line specifies that we want to retrieve the tweet_id column from the Tweets table. The tweet_id represents the unique identifier for each tweet. 这一行指定了我们要从 Tweets 表中获取 tweet_id 列,tweet_id 是每条推文的唯一标识符。 FROM Tweets…
-
Leetcode SQL: 1148. Article Views
•
1148. Article Views I Corrected SQL Code: SELECT DISTINCT [author_id] AS id FROM Views WITH (NOLOCK) WHERE author_id = viewer_id ORDER BY [author_id]; Explanation: SELECT DISTINCT [author_id] AS id: We are selecting the author_id column from the Views table, but we are using the DISTINCT keyword to ensure that only…
-
Leetcode SQL: 595: Big Countries
•
595. Big Countries SQL Code: SELECT [name], [population], [area] FROM World (NOLOCK) WHERE area >= 3000000 OR population >=25000000 Explanation: SELECT name, population, area: This line specifies that we want to retrieve three columns: name, population, and area from the World table. name: Represents the name of the country. population:…
-
Leetcode SQL: 584. Find Customer Referee
•
584. Find Customer Referee Corrected SQL Code: SELECT name FROM Customer WHERE referee_id IS NULL OR referee_id != 2; Explanation: SELECT name: This specifies that we want to retrieve the name column from the Customers table, which holds the names of the customers. 这一行指定了我们要从 Customers 表中获取 name 列,name 表示客户的名字。 FROM…
-
Leetcode SQL: 1757. Recyclable and Low Fat Products
•
1757. Recyclable and Low Fat Products Improved SQL Code: SELECT product_id FROM Products WITH (NOLOCK) WHERE low_fats = 'Y' AND recyclable = 'Y' AND product_id IS NOT NULL; Explanation: SELECT product_id: We are selecting the product_id column from the Products table. This column contains the unique identifiers for each product.…