11 2018 档案
[Leetcode 40]组合数和II Combination Sum II
摘要:【题目】 Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate
阅读全文
[Leetcode 39]组合数的和Combination Sum
摘要:【题目】 Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where
阅读全文
[Leetcode 72]编辑距离 Edit Distance
摘要:【题目】 Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2. You have the following 3 operations pe
阅读全文
[Leetcode 452] 最少需要射出多少支箭Minimum Number of Arrows to Burst Balloons 贪心 重载
摘要:【题目】 There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of th
阅读全文
[Leetcode 216]求给定和的数集合 Combination Sum III
摘要:【题目】 Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination shoul
阅读全文
[Leetcode 217&219]寻找数组中的重复值Contains Duplicate I & II
摘要:【题目1】 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in t
阅读全文
[Leetcode easy]存些水题34、20、700
摘要:leetcode 34 最早出现和最后出现 class Solution { public int[] searchRange(int[] nums, int target) { int []ans={-1,-1} ; for(int i=0;i<nums.length;i++){ if(nums[
阅读全文
[Leetcode 37]*数独游戏 Sudoku Solver 附解释
摘要:【题目】 每一行、每一列、每个3*3的格子里只能出现一次1~9。 【思路】 参考了思路,附加了解释。 dfs遍历所有非空格子,n是已经填好的个数。 初始化条件。n=81,都填了,返回结束。对于已经填好的b[x][y] != '.'跳过,到下一个。 xy的设计保证先行后列填写。 开始填数字,valid
阅读全文
[Leetcode 134]汽车加油站 Gas Station (环形)
摘要:【题目】 There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it
阅读全文
[Leetcode 18]四数之和 4 Sum
摘要:【题目】 Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all uni
阅读全文
[Leetcode 771]宝石和石子 Jewels and Stones HashSet简单应用
摘要:【题目】 You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of
阅读全文
[Leetcode 46]全排列 Permutations 递归
摘要:【题目】 Given a collection of distinct integers, return all possible permutations. 数组的组合情况。 【思路】 求子集,排列组合的数组题有固定模板。 【代码】
阅读全文
[Leetcode 90]求含有重复数的子集 Subset II
摘要:【题目】 Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not
阅读全文
[Leetcode 78]求子集 Subset
摘要:【题目】 Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. 求
阅读全文
[Leetcode 15]三数之和 3 Sum
摘要:【题目】 Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives
阅读全文
[Leetcode 144]二叉树前序遍历Binary Tree Preorder Traversal
摘要:【题目】 Given a binary tree, return the preordertraversal of its nodes' values. Example: 【思路】 有参考,好机智,使用堆栈压入右子树,暂时存储。 左子树遍历完成后遍历右子树。 【代码】
阅读全文
[Leetcode 108]有序数组转二叉搜索树Convert Sorted Array to Binary Search Tree
摘要:【题目】 给出的升序排序的数组,个数必为奇数,要求形成二叉搜索(平衡)树。 【思路】 辅助函数fun,[0,len]=>[0,mid-1]+[mid+1,len]。 当left>right,返回null。 【AC代码】
阅读全文
[Leetcode 105]*前序后序遍历形成树
摘要:so basically flag-start is size of the roots left subtree, therefore to get the start of right subtree you gotta get to the start of the first value o
阅读全文
[Leetcode221]最大面积 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. Example: 【思路】 【代码】
阅读全文
[Leetcode 739]*还有几天会升温 Daily Temperatures
摘要:【题目】 Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a
阅读全文
[Leetcode 135]糖果分配 Candy
摘要:【题目】 There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the followi
阅读全文
[Leetcode 101]判断对称树 Symmetric Tree
摘要:【题目】 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is s
阅读全文
[Leetcode 100]判断二叉树相同 Same Tree
摘要:【题目】 判断二叉树是否相同。 【思路】 check函数。 p==null并且q==null,返回true;(两边完全匹配) p==null或q==null,返回false;(p、q其中一方更短) p.val==q.val,值相同,继续迭代向左向右遍历check(p.left,q.left)&&ch
阅读全文
[Leetcode 392]判断子序列 Is Subsequence
摘要:【思路】 判断s是否为t的子串,所以length(s)<=length(t)。于是两个指针,一次循环。 将s、t转换为数组p1、p2。 i为过程中s的匹配长度。 i=0空串,单独讨论返回true。 当i=p1.length-1时返回true,否则循环结束返回false。 【代码】 【举例】
阅读全文
[Leetcode 376]摇摆序列 Wiggle Subsequence
摘要:【题目】 A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative.
阅读全文
[leetcode整理]
摘要:简单 leetcode164 Maximum Gap sort两次 有参考 330 Patching Array 98 Validate Binary Search Tree BFS 60 Subsets II [done] 435 non-overlapping 455. Assign Cooki
阅读全文
[整理]Kadane算法
摘要:仅能操作一次时,需每次观察是否有为负情况置零。多次操作时,仅需判断是否后者大于前者。 leetcode 53、121、122 【代码】 class Solution { public int maxSubArray(int[] nums) { int sum=Integer.MIN_VALUE; i
阅读全文
[Leetcode 122]买股票II Best Time to Buy and Sell Stock II
摘要:【题目】 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 c
阅读全文
[Leetcode 881]船救人 Boats to Save People 贪心
摘要:【题目】 The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat carries at most 2 people at the same time, pro
阅读全文
[Leetcode 62]机器人走路Unique Path 动态规划
摘要:【题目】 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at
阅读全文
[Leetcode 70]爬梯子 Climbing Stairs
摘要:【题目】 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can y
阅读全文
[leetcode121]股票买卖 Best Time to Buy and Sell Kadane算法
摘要:【题目】 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transa
阅读全文
[leetcode53]最长子数组 Maximum Subarray Kadane's算法
摘要:【题目】 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example:
阅读全文
浙公网安备 33010602011771号