LeetCode Rising Temperature
Problem 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, retur...
常用数据结构、双指针滑动窗口、动态规划与二分搜索。
Problem 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, retur...
Problem Implement the following operations of a queue using stacks. Example: Notes: You must use only standard operations of a stack -- which means only push to...
Problem Given an integer, write a function to determine if it is a power of two. Example 1: Example 2: Example 3: 判断一个整数是否是2的幂次方 <!--break-- Python3 分析 给出两种办法。一...
Problem Invert a binary tree. Example: 对树进行完全的左右节点交换 <!--break-- Python3 分析 很自然的想到了递归
Problem Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top(...
Problem Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the ab...
Problem Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array...
Problem Reverse a singly linked list. Example: Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both? 即反转链表,建议采用递...
Problem Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences...
Problem Description: Count the number of prime numbers less than a non-negative number, n. 即统计小于n的质数个数 <!--break-- Python3 分析 采用空间换时间的方式。否则会超时。
Problem Remove all elements from a linked list of integers that have value val. Example Given: 1 -- 2 -- 6 -- 3 -- 4 -- 5 -- 6, val = 6 Return: 1 -- 2 -- 3 -- 4...
Problem Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer,...
Problem You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you...
Problem 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 line,...
Problem 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, after...
Problem 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 a...
Problem Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit in...
Problem Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return...
Problem Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note:...
Problem Write a SQL query to get the nth highest salary from the Employee table. For example, given the above Employee table, the nth highest salary where n = 2...
Problem 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 Empl...
Problem 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: 找到重复的Em...
Problem 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....
Problem Write a SQL query to get the second highest salary from the Employee table. For example, given the above Employee table, the query should return 200 as...
Problem Table: Person Table: Address Write a SQL query for a report that provides the following information for each person in the Person table, regardless if t...
Problem Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 即计算n!末尾0的个数。要求用对数时间复杂度 <!-...
Problem Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the a...
Problem Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 即生成Excel表格的表头 <!--break-- Python 实现 分析 讲不出太多道理...
Problem Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: 即从Ex...
Problem Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function t...
Problem Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin to inte...
Problem Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes...
Problem Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up: Can you...
Problem Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 判断一个链表中是否存在 环,不开辟额外的空间 <!--break-- Python...
Problem Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm sho...
Problem Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexi...
Problem Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Pana...
Problem Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (...
Problem Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete...
Problem Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to us...
Problem Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return 没记错的话,这个应该叫杨辉三角型。很简单的题 <!--break-- Python 实现 分析 没...
Problem Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum...
Problem Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For...
Problem Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest lea...
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(...
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers suc...
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcb...
![LeetCode[Algorithms] Longest Substring Without Repeating Characters]({{ site.url }}/images/longestsubstringwithoutrepeatingcharacters.png)
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add...
<p 一般存储矩阵,自然想到二维数据。但是对于稀疏矩阵(0项很多),这无疑浪费的大量的空间。所以,这里考虑换一种表示方法。用一个三元组表示矩阵中的非零元素。</p <p style="text-align: center;" <img alt="" src="/images/oldposts/a7iq6.jpg" st...