leetcode秋季赛第3题-秋叶收藏集 这题看了答案之后一直在想为什么能这么转移 后来一想,对于每一个长度的leaves,去掉最后一片树叶之后,只有可能是三种排列,也就是 rrrrr rryy rryyrr 因此转移就相当于分解成n-1个和最后一个分别求最小次数后相加,因为当前状态只可能从前一步的 ...
分类:
其他好文 时间:
2020-09-17 23:49:36
阅读次数:
29
package LeetCode_463 /** * 463. Island Perimeter * https://leetcode.com/problems/island-perimeter/description/ * * You are given row x col grid repres ...
分类:
其他好文 时间:
2020-09-17 23:30:18
阅读次数:
36
克隆图 LeetCode-133 使用一个map来存储已经遍历的结点,这个存起来的结点必须是新new的才符合题意 /* // Definition for a Node. class Node { public int val; public List<Node> neighbors; public ...
分类:
其他好文 时间:
2020-09-17 23:15:52
阅读次数:
29
本文是对leetcode回溯题的一些模板进行整理总结,很多关于回溯的blog都会引用对回溯算法的official definition和通用的解题步骤,如果是真的想研究这一算法思想,按照这样的方式来完全没有问题。不过个人觉得如果仅仅只是为了应试,那么掌握一些解题的模板会更直接的帮助理解回溯的算法思想 ...
分类:
编程语言 时间:
2020-09-17 22:58:48
阅读次数:
37
int* plusOne(int* digits, int digitsSize, int* returnSize){ int i,carry=1; int* arr = (int*)calloc(digitsSize+1,sizeof(int)); for (i=digitsSize-1; i>= ...
分类:
其他好文 时间:
2020-09-17 22:54:01
阅读次数:
25
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time ...
分类:
其他好文 时间:
2020-09-17 22:49:35
阅读次数:
38
题目如下: Given an array nums, you are allowed to choose one element of nums and change it by any value in one move. Return the minimum difference between ...
分类:
其他好文 时间:
2020-09-17 22:48:12
阅读次数:
35
问题描述 给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。 你的算法时间复杂度必须是 O(log n) 级别。 如果数组中不存在目标值,返回 [-1, -1]。 示例 1: 输入: nums = [5,7,7,8,8,10], tar ...
分类:
编程语言 时间:
2020-09-17 21:50:55
阅读次数:
30
每天 3 分钟,走上算法的逆袭之路。 前文合集 每日一道 LeetCode 前文合集 代码仓库 GitHub: https://github.com/meteor1993/LeetCode Gitee: https://gitee.com/inwsy/LeetCode 题目:翻转二进制数 题目来源: ...
分类:
其他好文 时间:
2020-09-17 21:35:31
阅读次数:
34
dfs暴力,也就是二进制枚举的思想,也就是枚举所有的情况,这个题目有个很好的剪枝,就是先排序,然后在 这样可以避免答案出现相同的组合。 code: class Solution { public: int p[1000]; vector<vector<int>> ans; vector<int> v ...
分类:
其他好文 时间:
2020-09-17 21:24:53
阅读次数:
42