随笔分类 - leetcode
[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
阅读全文
浙公网安备 33010602011771号