随笔分类 - LeetCode
记录LeetCode网站中已完成的题目
摘要:Description:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents...
阅读全文
摘要:Description:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Code:#define NU...
阅读全文
摘要:Description:Given an integern, return all distinct solutions to then-queens puzzle.Each solution contains a distinct board configuration of then-queen...
阅读全文
摘要:Description:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeatin...
阅读全文
摘要:Description:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one uniqu...
阅读全文
摘要:Description:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S=...
阅读全文
摘要:Description:Write a function to find the longest common prefix string amongst an array of strings.(最长公共字串)Code:string merge(string&str1, string&str2) ...
阅读全文
摘要:Description:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeatin...
阅读全文
摘要:Description:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Code1:vector g...
阅读全文
摘要:Description:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n =...
阅读全文
摘要:Description:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element fro...
阅读全文
摘要:Description:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf pat...
阅读全文
摘要:Description:Given an array of numbersnums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the tw...
阅读全文
摘要:Description:Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, ...
阅读全文
摘要:Description:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals we...
阅读全文
摘要:Description:Sort a linked list using insertion sort.Code: ListNode* insertionSortList(ListNode* head) { if (head == NULL) return NUL...
阅读全文
摘要:Description:Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].Co...
阅读全文
摘要:Description:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and i...
阅读全文
摘要:Description: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 t...
阅读全文
摘要:Description:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twic...
阅读全文