随笔分类 - leetcode
摘要:Question Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Solution 这道题用穷举法求解,时间复杂度为O(n^2)。但是要注意几个细节
阅读全文
摘要:Question Given a binary tree containing digits from0 9only, each root to leaf path could represent a number. An example is the root to leaf path1 2 3w
阅读全文
摘要:Question Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally id
阅读全文
摘要:Question Given a binary tree, determine if it is height balanced. For this problem, a height balanced binary tree is defined as a binary tree in which
阅读全文
摘要:Question Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a
阅读全文
摘要:Question Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. F
阅读全文
摘要:Question There are N gas stations along a circular route, where the amount of gas at station i isgas[i]. You have a car with an unlimited gas tank and
阅读全文
摘要:Question Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? Solution 判断一个链表是否有环,可以采用slow f
阅读全文
摘要:Question Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using ext
阅读全文
摘要:LeetCode——Insertion Sort List Question Sort a linked list using insertion sort. Solution 我的解法,假设第一个节点都比其他节点小,这样感觉好移动指针一些,所以添加了一个额外的最小的节点。 Code
阅读全文
摘要:LeetCode— Sort List Question Sort a linked list in O(n log n) time using constant space complexity. Solution 看到对链表的排序,时间复杂度O(n log n),首先想到的就是归并排序。 但是这
阅读全文
摘要:LeetCode——Longest Consecutive Sequence Question Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For
阅读全文
摘要:LeetCode——single number系列 Question 1 Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorith
阅读全文
摘要:LeetCode——Word Break Question Given a non empty string s and a dictionary wordDict containing a list of non empty words, determine if s can be segment
阅读全文
摘要:LeetCode——Move Zeroes Question Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non
阅读全文
摘要:LeetCode——Construct the Rectangle Question For a web developer, it is very important to know how to design a web page's size. So, given a specific rec
阅读全文
摘要:LeetCode——Add Digits Question Given a non negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given
阅读全文
摘要:LeetCode—— Invert Binary Tree Question invert a binary tree. Trivia: This problem was inspired by this original tweet by Max Howell: Google: 90% of ou
阅读全文
摘要:LeetCode——Sum of Two Integers Question Calculate the sum of two integers a and b, but you are not allowed to use the operator + and . Example: Given a
阅读全文
摘要:LeetCode——Find the Difference Question Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling st
阅读全文