随笔分类 - LeetCode
1
LeetCode上一些习题相应的题解
摘要:题目: 证明: 很容易将最小顶点覆盖归约到HITTING SET。假设要求图G的最小顶点覆盖,可以建立一个 HITTING SET 实例,其中 S1 , S2 , S3,...,Sn 即是图G的各条边,比如{v1,v2},{v3,v4},... 。通过二分式的询问,可以找到一个与 Si都相交的最小集
阅读全文
摘要:题目: 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 co
阅读全文
摘要:题目: 107. Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to
阅读全文
摘要:题目:108. Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 题
阅读全文
摘要:111. Minimum Depth of Binary Tree 问题描述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path
阅读全文
摘要:题目: Given an array of strings, group anagrams together. (给定一个字符串数组,将他们根据anagram归类) 样例: given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [["a
阅读全文
摘要:题目: Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest
阅读全文
摘要:题目: You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both t
阅读全文
摘要:原题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: Given an encoded message containing digits, determ
阅读全文
摘要:Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5,
阅读全文
摘要:Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. 示例: Note: 题解: 看着题目的注意事项就
阅读全文
摘要:题目: Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum
阅读全文
摘要:本周继续练习动态规划的相关题目。 题目: In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue. For now, su
阅读全文
摘要:本周课堂上学习的是动态规划,因此在LeetCode上找到相应的题进行练习。 题目: Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum le
阅读全文
摘要:本周选择了贪心算法类的题型加以巩固,在LeetCode中难度系数为Hard。 题目: Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, L
阅读全文
摘要:本周依旧是做与图论相关的题目,作为对图论知识的巩固。 题目:279. Perfect Squares Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9,
阅读全文
摘要:本周学习了DFS,因此在LeetCode中挑选了一道关于DFS的题目作为巩固。 题目:200. Number of Islands Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An
阅读全文
摘要:本周对链表操作进行了巩固 题目: Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the n
阅读全文
摘要:本周学习分治法,故特意挑选了相关习题巩固一下,并回顾一下分治法的思路 题目:Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is the kth large
阅读全文
摘要:题目: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes co
阅读全文
1