
算法与数据结构
tzy1997
仍未忘相约看漫天黄叶远飞
展开
-
A1042.Shuffling Machine(20)
题目描述:Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with ga...原创 2018-04-17 20:45:06 · 265 阅读 · 0 评论 -
Leet123. 买卖股票的最佳时机 III(Best Time to Buy and Sell Stock III)
https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii/description/public int maxProfit(int[] prices) { if(prices.length==0) { return 0; } ...原创 2018-10-06 13:40:15 · 152 阅读 · 0 评论 -
Leet34. 在排序数组中查找元素的第一个和最后一个位置(Find First and Last Position of Element in Sorted Array)
https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/description/class Solution { public static int[] searchRange(int[] nums, int target) { int...原创 2018-10-06 19:33:33 · 195 阅读 · 0 评论 -
Leet322. 零钱兑换(Coin Change)
https://leetcode-cn.com/problems/coin-change/description/public static int coinChange(int[] coins, int amount) { //dp[amount]=min(dp[amount-coins[i]])+1 if(amount==0) {...原创 2018-10-07 13:42:14 · 189 阅读 · 0 评论 -
Leet503. 下一个更大元素 II(Next Greater Element II)
https://leetcode-cn.com/problems/next-greater-element-ii/description/class Solution {public int[] nextGreaterElements(int []nums) { int res[]=new int[nums.length]; if(nums.leng...原创 2018-10-08 14:37:14 · 298 阅读 · 0 评论 -
Leet718.最长重复子数组(Maximum Length of Repeated Subarray)
https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/description/动态规划 维护当前存在的最长重复子数组public int findLength(int[] A, int[] B) { int res=0; int temp[][]=new int[...原创 2018-10-15 17:00:03 · 216 阅读 · 0 评论 -
Leet46. 全排列(Permutations)
https://leetcode-cn.com/problems/permutations/description/class Solution {public List<List<Integer>> permute(int[] nums) { List<List<Integer>> res=new ArrayList&l...原创 2018-11-04 20:56:14 · 148 阅读 · 0 评论 -
剑指offer解题记录(JAVA)
面试题3:数组中重复的数字题目链接import java.util.Arrays;/** * P39 面试题3:数组中重复的数字 * 在一个长度为n的数组里所有数字都在0~n-1的范围内 数组中某些数字是重复的 但不知道有几个数字重复了 * 也不知道每个数字重复了几次 请找出数组中任意一个重复的数字 * 例如 如果输入长度为7的数组{2,3,1,0,2,5,3} * 那么对...原创 2018-12-24 15:59:28 · 606 阅读 · 0 评论 -
Leet343.整数拆分(Integer Break)
/* * P96面试题14:剪绳子 * 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积 */public class T14{ /* * 解法一:动态规划 * 令dp[n]为n对应的最大乘积 * 维护这个最优解数组 * 注释中的写法是另一种理解方式 * 当拆分出的一部分的长度为4时 这一段是否需要再进行拆分?...原创 2019-01-13 15:53:31 · 256 阅读 · 0 评论 -
Leet122. 买卖股票的最佳时机 II(Best Time to Buy and Sell Stock II)
https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/description/public int maxProfit(int[] prices) { int res=0; for(int i=0;i<prices.length-1;i++) {...原创 2018-10-06 13:40:33 · 149 阅读 · 0 评论 -
Leet121. 买卖股票的最佳时机(Best Time to Buy and Sell Stock)
https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/description/public static int maxProfit(int[] prices) { int maxEar=0; for(int i=prices.length-1;i>0;i--) ...原创 2018-10-06 13:40:43 · 156 阅读 · 0 评论 -
Leet724.寻找数组的中心索引(Find Pivot Index)
https://leetcode-cn.com/problems/find-pivot-index/description/class Solution { public int pivotIndex(int[] nums) { int sum=0; for(int i=0;i<nums.length;i++) { ...原创 2018-10-02 17:05:25 · 154 阅读 · 0 评论 -
A1011.World Cup Betting(20)
题目描述:With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Afric...原创 2018-04-18 20:42:59 · 129 阅读 · 0 评论 -
A1144. The Missing Number (20)
题目描述:Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.输入格式:Each input file contains one test case. For each case, the first line gives a positive ...原创 2018-04-23 21:17:23 · 220 阅读 · 0 评论 -
A1048. Find Coins (25)
题目描述:Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. How...原创 2018-05-05 20:58:44 · 169 阅读 · 0 评论 -
Leet459.重复的子字符串( Repeated Substring Pattern)
https://leetcode-cn.com/problems/repeated-substring-pattern/description/Java:public static boolean repeatedSubstringPattern(String s) { //由于取余问题首先排除全部由单个字符组成的特例 if(s.length()==1) {...原创 2018-08-13 15:11:11 · 178 阅读 · 0 评论 -
Leet234.回文链表(Palindrome Linked List)
https://leetcode-cn.com/problems/palindrome-linked-list/description//** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x)...原创 2018-08-13 17:02:09 · 157 阅读 · 0 评论 -
Leet754. 到达终点数字(Reach a Number)
https://leetcode-cn.com/problems/reach-a-number/description/public static int reachNumber(int target) { //1+2+3+4+5+6......+max=target //先确认全加/全减情况下 大于/小于target的极端情况 int times=1; int s...原创 2018-08-19 19:10:04 · 528 阅读 · 0 评论 -
Leet515.在每个树行中找最大值(Find Largest Value in Each Tree Row)
https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/description//** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tr...原创 2018-10-01 11:09:20 · 275 阅读 · 0 评论 -
Leet.473火柴拼正方形(Matchsticks to Square)
https://leetcode-cn.com/problems/matchsticks-to-square/description/思路:这道题的相对难点在于求得边长后 可能有很多条火柴来构成这条边 而被使用的火柴不能再次使用若某次使用了某一根火柴 则可能导致另一条本能够凑成的边无法凑得 所以需要回溯到上一次选择看到这里首先想到(只想到)的方法是用DFS来实现可以说是...原创 2018-10-01 12:23:34 · 391 阅读 · 0 评论 -
堆排序思路及非递归Java实现
参考左程云的视频1.完全二叉树的概念在了解堆排序的最开始,需要明白什么是完全二叉树对于这样一棵用编号代表节点的树,若这棵树的节点严格按照图中的顺序填充(不必填满),即称为完全二叉树也就是说,除了最后一层之外的每一层都被完全填满,而最后一层的所有节点,都需要保持从左到右的顺序以上面这个图举例:若去掉节点12 13 14 15,该树满足完全二叉树但是若去掉...原创 2019-08-20 19:30:58 · 345 阅读 · 0 评论