
LeetCode
文章平均质量分 57
两鬓已不能斑白
这个作者很懒,什么都没留下…
展开
-
125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindr原创 2017-05-21 17:02:30 · 342 阅读 · 0 评论 -
蛇形矩阵
题目描述 蛇形矩阵是由1开始的自然数依次排列成的一个矩阵上三角形。 样例输入 5 样例输出 1 3 6 10 15 2 5 9 14 4 8 13 7 12 11思路: 找规律,写了两层for循环Java 代码:import java.util.*;public class Main { public static vo原创 2017-07-01 20:56:53 · 565 阅读 · 1 评论 -
Leetcode 415. Add Strings
Leetcode 415. Add Strings Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.Note: The length of both num1 and num2 is < 5100.Both num1 an原创 2017-08-30 10:19:51 · 627 阅读 · 0 评论 -
Leetcode 653. Two Sum IV - Input is a BST
Leetcode 653. Two Sum IV - Input is a BST—————————————– Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the g原创 2017-08-30 09:38:05 · 1980 阅读 · 0 评论 -
LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search Tree Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikip原创 2017-08-28 16:51:35 · 650 阅读 · 0 评论 -
LeetCode 236. Lowest Common Ancestor of a Binary Tree
LeetCode 236. Lowest Common Ancestor of a Binary Tree Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia:原创 2017-08-28 16:43:59 · 1210 阅读 · 0 评论 -
Leetcode 67. Add Binary
Leetcode 67. Add Binary———————– Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".思路:用字符串模拟二进制加法,代码如下:class Solution { public Str原创 2017-08-30 10:34:37 · 348 阅读 · 0 评论 -
1、Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same ele原创 2017-08-28 15:14:32 · 1307 阅读 · 0 评论 -
Leetcode 523.Continuous Subarray Sum
Leetcode 523.Continuous Subarray Sum Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums原创 2017-09-01 10:26:56 · 623 阅读 · 0 评论 -
Leetcode 53. Maximum Subarray
Leetcode 53. Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the原创 2017-09-01 13:38:32 · 563 阅读 · 0 评论 -
27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The orde原创 2017-06-14 23:26:46 · 332 阅读 · 0 评论 -
Leetcode 560. Subarray Sum Equals K
Subarray Sum Equals K Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Output:原创 2017-09-01 13:02:21 · 377 阅读 · 0 评论 -
Leetcode 98. Validate Binary Search Tree
Leetcode 98. Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only no原创 2017-09-04 09:16:14 · 654 阅读 · 0 评论 -
234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?思路:快慢指针找到中点,同时修改前一半链表的.next,然后从中间开始向链表两端比较。/** * Definition for singly-linked list.原创 2017-05-21 19:46:39 · 262 阅读 · 0 评论 -
221. Maximal Square
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Return原创 2017-05-22 08:33:10 · 318 阅读 · 0 评论 -
79. Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically nei原创 2017-07-13 12:10:47 · 339 阅读 · 0 评论 -
530. Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes. Example: Input: 1 \ 3 / 2Output: 1Explanation: The m原创 2017-07-13 14:10:17 · 329 阅读 · 0 评论 -
Leetcode 606. Construct String from Binary Tree
Leetcode 606. Construct String from Binary Tree———————————————– You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null原创 2017-07-04 13:12:21 · 1509 阅读 · 0 评论 -
599. Minimum Index Sum of Two Lists
599. Minimum Index Sum of Two Lists Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need原创 2017-07-06 17:06:18 · 593 阅读 · 0 评论 -
637. Average of Levels in Binary Tree
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explanation:T原创 2017-07-17 21:17:54 · 1182 阅读 · 0 评论 -
538. Convert BST to Greater Tree
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.原创 2017-07-18 15:12:46 · 421 阅读 · 0 评论 -
171. Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26原创 2017-07-18 23:22:54 · 515 阅读 · 0 评论 -
263. Ugly Number
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is no原创 2017-07-19 23:30:20 · 391 阅读 · 0 评论 -
128. Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3, 4].原创 2017-06-02 09:09:53 · 377 阅读 · 0 评论 -
Leetcode35.Search Insert Position
题目描述 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in th原创 2017-10-30 15:11:07 · 294 阅读 · 0 评论 -
SQL join、left join小例子
最近在刷Leetcode中,遇到两道SQL小题,记录在此 join小例子: 181. Employees Earning More Than Their Managers 197. Rising Temperature left join 小例子: 175. Combine Two Tables181. Employees Earning More...原创 2018-09-09 08:27:33 · 1460 阅读 · 0 评论 -
783. Minimum Distance Between BST Nodes
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree.Example :Input: root = [4,2,6,1,3,null,null...原创 2018-09-09 09:13:58 · 284 阅读 · 0 评论 -
leetcode 广搜小题两道
leetcode 广搜小题两道周末无聊,故刷两道小题,用的都是广搜的思想Minimum Depth of Binary TreeGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node ...原创 2018-09-22 23:49:43 · 431 阅读 · 0 评论 -
Leetcode 703.Kth Largest Element in a Stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.Your KthLargest class will have a constructor whi...原创 2018-11-03 22:52:13 · 363 阅读 · 0 评论 -
338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example 1:Input: 2Output...原创 2018-11-11 17:32:36 · 258 阅读 · 0 评论 -
Leetcode 946. Validate Stack Sequences
Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.Example 1:...原创 2018-12-23 16:14:50 · 487 阅读 · 0 评论 -
Leetcode 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5Exampl...原创 2018-12-31 00:27:07 · 223 阅读 · 0 评论 -
692. Top K Frequent Words:HashMap排序
因为平时工作中较少能接触到HashMap的排序,因此周末借由一道leetcode上的小题,再写一写HashMap的排序代码,特此记录。原题如下:Top K Frequent WordsGiven a non-empty list of words, return the k most frequent elements.Your answer should be sorted by f...原创 2019-01-06 11:23:48 · 529 阅读 · 0 评论 -
LeetCode刷题笔记目录
1、Two Sumhttps://blog.youkuaiyun.com/u010429424/article/details/7764898927、Remove Elementhttps://blog.youkuaiyun.com/u010429424/article/details/7326056453、Maximum Subarrayhttps://blog.youkuaiyun.com/u010429424/art...原创 2019-03-01 22:59:39 · 518 阅读 · 0 评论 -
942. DI String Match
942. DI String Match下班到家后,刷了刷leetcode,发现了一道很有意思的小题,题目如下:Given a string S that only contains “I” (increase) or “D” (decrease), let N = S.length.Return any permutation A of [0, 1, …, N] such that fo...原创 2019-03-26 22:38:39 · 282 阅读 · 0 评论 -
690. Employee Importance
You are given a data structure of employee information, which includes the employee’s unique id, his importance value and his direct subordinates’ id. For example, employee 1 is the leader of employ...原创 2018-09-08 23:35:06 · 239 阅读 · 0 评论 -
888. Fair Candy Swap
**888. Fair Candy Swap**Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Alice has, and B[j] is the size of the j-th bar of candy that Bob has.Since...原创 2018-08-25 10:56:36 · 518 阅读 · 0 评论 -
Leetcode. 682. Baseball Game
682. Baseball Game You’re now a baseball game point recorder.Given a list of strings, each string can be one of the 4 following types:Integer (one round’s score): Directly represents the numbe原创 2017-10-13 19:30:23 · 741 阅读 · 0 评论 -
88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional原创 2017-11-15 20:40:22 · 324 阅读 · 0 评论 -
北京工作前一天
今天是2018年1月8日,于沈阳,2018年的第一场大雪,明天就要去北京正式工作了,下午等友人,无聊,故刷Leetcode小题~第1题、728. Self Dividing NumbersA self-dividing number is a number that is divisible by every digit it contains.For example, 128 is原创 2018-01-08 14:14:48 · 584 阅读 · 0 评论