LeetCode
文章平均质量分 54
ov大鱼vo
我们的远方是星辰大海
展开
-
390. 消除游戏
列表 arr 由在范围 [1, n] 中的所有整数组成,并按严格递增排序。请你对 arr 应用下述算法:从左到右,删除第一个数字,然后每隔一个数字删除一个,直到到达列表末尾。重复上面的步骤,但这次是从右到左。也就是,删除最右侧的数字,然后剩下的数字每隔一个删除一个。不断重复这两步,从左到右和从右到左交替进行,直到只剩下一个数字。给你整数 n ,返回 arr 最后剩下的数字。示例 1:输入:n = 9输出:6解释:arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]arr =原创 2022-01-02 15:36:16 · 1493 阅读 · 0 评论 -
LeetCode 299. Bulls and Cows
分析难度 中来源 https://leetcode.com/problems/bulls-and-cows/题目You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is....原创 2019-02-24 11:15:32 · 207 阅读 · 0 评论 -
LeetCode 313. Super Ugly Number
分析难度 中来源 https://leetcode.com/problems/super-ugly-number/题目Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime...原创 2019-02-18 20:46:10 · 130 阅读 · 0 评论 -
LeetCode 264. Ugly Number II
分析难度 中来源 https://leetcode.com/problems/ugly-number-ii/题目Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.Example:Input: n ...原创 2019-02-18 20:18:00 · 113 阅读 · 0 评论 -
LeetCode 289. Game of Life
分析难度 中来源 https://leetcode.com/problems/game-of-life/思路To solve it in place, we use 2 bits to store 2 states: [2nd bit, 1stbit] = [next state, current state]00 dead (next) <- dead (current)...原创 2019-02-23 15:39:32 · 176 阅读 · 0 评论 -
LeetCode 508. Most Frequent Subtree Sum
分析难度 中来源 https://leetcode.com/problems/most-frequent-subtree-sum/题目Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of...原创 2019-02-16 22:44:11 · 165 阅读 · 0 评论 -
LeetCode 275. H-Index II
分析难度 中来源 https://leetcode.com/problems/h-index-ii/题目Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the...原创 2019-02-22 09:58:05 · 175 阅读 · 0 评论 -
LeetCode 647. Palindromic Substrings
分析难度 中来源 https://leetcode.com/problems/palindromic-substrings/题目Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or...原创 2019-02-16 11:09:27 · 186 阅读 · 0 评论 -
LeetCode 193. Valid Phone Numbers
分析难度 易来源https://leetcode.com/problems/valid-phone-numbers/题目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 n...原创 2018-11-26 20:39:39 · 241 阅读 · 0 评论 -
LeetCode 192. Word Frequency
分析难度 中来源https://leetcode.com/problems/word-frequency/题目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 conta...原创 2018-11-26 16:23:01 · 129 阅读 · 0 评论 -
LeetCode 191. Number of 1 Bits
分析难度 易来源https://leetcode.com/problems/number-of-1-bits/题目Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight).Example 1:I...原创 2018-11-25 20:23:42 · 109 阅读 · 0 评论 -
LeetCode 190. Reverse Bits
分析难度 易来源https://leetcode.com/problems/reverse-bits/submissions/题目Reverse bits of a given 32 bits unsigned integer.Example:Input: 43261596Output: 964176192Explanation: 43261596 represented in ...原创 2018-11-25 20:09:42 · 101 阅读 · 0 评论 -
LeetCode 183. Customers Who Never Order
分析难度 易来源https://leetcode.com/problems/customers-who-never-order/题目Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who...原创 2018-11-18 11:03:20 · 111 阅读 · 0 评论 -
LeetCode 175. Combine Two Tables
分析难度 易来源https://leetcode.com/problems/combine-two-tables/SQL LEFT JOIN 关键字LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行。LEFT JOIN 关键字语法SELECT column_name(s)FROM table_n...原创 2018-11-16 15:07:24 · 108 阅读 · 0 评论 -
LeetCode 172. Factorial Trailing Zeroes
分析难度 易来源https://leetcode.com/problems/factorial-trailing-zeroes/题目Given an integer n, return the number of trailing zeroes in n!.Example 1:Input: 3Output: 0Explanation: 3! = 6, no trailing ze...原创 2018-11-16 11:16:39 · 111 阅读 · 0 评论 -
LeetCode 189. Rotate Array
分析难度 易来源https://leetcode.com/problems/rotate-array/submissions/题目Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Out...原创 2018-11-18 22:37:28 · 119 阅读 · 0 评论 -
LeetCode 167. Two Sum II - Input array is sorted
分析难度 易来源https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/题目Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific...原创 2018-11-12 16:21:57 · 109 阅读 · 0 评论 -
LeetCode 168. Excel Sheet Column Title
分析难度 易来源https://leetcode.com/problems/excel-sheet-column-title/十进制转26进制注意,z表示26,而非0题目Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:...原创 2018-11-12 17:33:54 · 106 阅读 · 0 评论 -
LeetCode 144. Binary Tree Preorder Traversal
分析难度 中来源 https://leetcode.com/problems/binary-tree-preorder-traversal/submissions/题目Given a binary tree, return the preorder traversal of its nodes’ values.Example:Input: [1,null,2,3]1 ...原创 2019-03-01 08:52:12 · 110 阅读 · 0 评论 -
LeetCode 355. Design Twitter
分析难度 中来源 https://leetcode.com/problems/design-twitter/题目Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweet...原创 2019-02-19 20:08:24 · 302 阅读 · 0 评论 -
构造二叉树
public TreeNode buildTree(Integer[] array){ TreeNode root=new TreeNode(array[0]);//假设array[0]不为null Queue&lt;TreeNode&gt; queue=new LinkedList&lt;TreeNode&gt;(); queue.offer(r...原创 2019-03-01 08:54:32 · 1159 阅读 · 0 评论 -
LeetCode 11. Container With Most Water
分析思路//左侧从左向右,右侧从右向左//如果左侧比右侧低,则左侧右侧之间的节点与左侧节点之间面积不必计算;//容器高度按左侧计算,宽度不及到右侧的宽度//可直接左侧右移//如果右侧壁左侧第,则左侧右侧之间的节点与右侧节点之间面积不必计算。//可直接右侧左移难度 Medium来源 https://leetcode.com/problems/container-with-most-wat...原创 2019-06-14 15:15:20 · 152 阅读 · 0 评论 -
LeetCode 310. Minimum Height Trees
分析难度 中来源 https://leetcode.com/problems/minimum-height-trees/题目For an undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among a...原创 2019-03-28 22:24:31 · 144 阅读 · 0 评论 -
LeetCode 64. Minimum Path Sum
分析难度 中来源 https://leetcode.com/problems/minimum-path-sum/题目Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers alon...原创 2019-03-28 21:33:42 · 245 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers
分析难度 中来源 https://leetcode.com/problems/add-two-numbers/题目You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their n...原创 2019-03-31 15:13:36 · 125 阅读 · 0 评论 -
LeetCode 309. Best Time to Buy and Sell Stock with Cooldown
分析难度 中来源 https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/题目Say you have an array for which the i th element is the price of a given stock on day i.Design an algorithm ...原创 2019-03-08 10:15:55 · 230 阅读 · 0 评论 -
LeetCode 307. Range Sum Query - Mutable
分析难度 中来源 https://leetcode.com/problems/range-sum-query-mutable/思路 https://blog.csdn.net/Jasmineaha/article/details/81462020使用树状数组(Binary Indexed Tree)其中A为普通数组,C为树状数组,奇数下标一定是叶子结点。相比线段树,所用空间更小,速度...原创 2019-03-07 16:55:35 · 165 阅读 · 0 评论 -
LeetCode 304. Range Sum Query 2D - Immutable
分析难度 中来源 https://leetcode.com/problems/range-sum-query-2d-immutable/题目Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and ...原创 2019-03-04 09:34:32 · 186 阅读 · 0 评论 -
LeetCode 274. H-Index
分析难度 中来源 https://leetcode.com/problems/h-index/思路1If we have the function f ordered in decreasing order from the largest value to the lowest one, we can compute the h index as follows:思路2 //The...原创 2019-02-21 11:00:19 · 192 阅读 · 0 评论 -
LeetCode 300. Longest Increasing Subsequence
分析难度 中来源 https://leetcode.com/problems/longest-increasing-subsequence/思路tails is an array storing the smallest tail of all increasing subsequences with length i+1 in tails[i].For example, say we ...原创 2019-03-02 18:05:49 · 349 阅读 · 0 评论 -
LeetCode 306. Additive Number
分析难度 中来源 https://leetcode.com/problems/additive-number/题目Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Excep...原创 2019-03-05 16:35:25 · 209 阅读 · 0 评论 -
LeetCode139. Word Break
分析难度 中来源 https://leetcode.com/problems/word-break/思路题目Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separ...原创 2019-02-26 13:32:01 · 166 阅读 · 0 评论 -
LeetCode 260. Single Number III
分析难度 中来源 https://leetcode.com/problems/single-number-iii/两种方式,位运算或者利用HashSethttps://leetcode.com/problems/single-number-iii/discuss/68901/Sharing-explanation-of-the-solutionThe two numbers that ...原创 2019-02-20 17:15:45 · 184 阅读 · 0 评论 -
LeetCode 143. Reorder List
分析难度 中来源 https://leetcode.com/problems/reorder-list/思路Find the middle of the listReverse the half after middleStart reorder one by one题目Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder...原创 2019-03-01 11:10:51 · 175 阅读 · 0 评论 -
LeetCode 138. Copy List with Random Pointer
分析难度 中来源 https://leetcode.com/problems/copy-list-with-random-pointer/思路Iterate the original list and duplicate each node. The duplicateof each node follows its original immediately.Iterate the ...原创 2019-02-25 15:26:07 · 202 阅读 · 0 评论 -
LeetCode 150. Evaluate Reverse Polish Notation
分析难度 中来源 https://leetcode.com/problems/evaluate-reverse-polish-notation/使用集合存储操作符,使用栈存储操作数,当下一个字符串为数字时,压栈;当下一个字符串记录操作符的时候,连续两次退栈,结合操作符计算结果,然后压栈题目Evaluate the value of an arithmetic expression in ...原创 2019-03-01 09:46:41 · 137 阅读 · 0 评论 -
打印二叉树
TreeNode实现同LeetCode:public class TreeNode { Integer val; TreeNode left; TreeNode right; //TreeNode(Integer x) { val = x; } TreeNode(int x) { val = x; left=null; ...原创 2019-03-01 08:57:55 · 1326 阅读 · 0 评论 -
LeetCode 171. Excel Sheet Column Number
分析难度 易来源https://leetcode.com/problems/excel-sheet-column-number题目Given a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C ->...原创 2018-11-14 10:38:33 · 147 阅读 · 0 评论 -
LeetCode 169. Majority Element
分析难度 易来源https://leetcode.com/problems/majority-element/题目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 ass...原创 2018-11-14 10:20:11 · 122 阅读 · 0 评论 -
LeetCode 287. Find the Duplicate Number
分析难度 中来源https://leetcode.com/problems/find-the-duplicate-number/题目Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicat...原创 2018-11-08 15:28:34 · 115 阅读 · 0 评论