自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

海口词典的博客

是否现在越无奈,过去越实在

  • 博客(26)
  • 资源 (1)
  • 收藏
  • 关注

原创 整数拆分

#include <iostream> using namespace std; int N,sum,num,a[25]; void dfs(int x) { if(sum>N) return; if(sum==N) { cout<<N<<"="<<a[0]; for(int i...

2019-11-22 22:01:33 172

原创 leetcode 三数之和为0

题目描述: 给定一个包含n个整数的数组nums,判断 nums中是否存在三个元素a,b,c ,使得a + b + c =0 ?找出所有满足条件且不重复的三元组。 注意:答案中不可以包含重复的三元组。 例如, 给定数组 nums = [-1, 0, 1, 2, -1, -4], 满足要求的三元组集合为: [ [-1, 0, 1], [-1, -1, 2] ] 具体思路:...

2019-11-12 21:20:50 204

原创 快速排序 C语言

算法原理 分治法的基本思想:将原问题分解为若干个更小的与原问题相似的问题,然后递归解决各个子问题,最后再将各个子问题的解组合成原问题的解。 利用分治法可以将解决办法分为“三步走”战略:(1)在数据集中选定一个元素作为“基准”(pivot)(2)将所有数据集小于基准的元素放在基准左边,大于基准的元素放在基准右边,把原数据集分为两个数据集的操作叫做“分区”,分区结束后基准所在的位置也就是基准...

2019-11-12 19:52:47 704

原创 leetcode 1072. 按列翻转得到最大值等行数

题目链接https://leetcode-cn.com/problems/flip-columns-for-maximum-number-of-equal-rows/ 题目看起来让人摸不着头脑,其实看懂题目就会变得特别的简单了。 1、首先该函数返回的最小的值应该是1 2、两行数字,经过对一些列的反转,最后都达到这一行的值的相同。那么这两行数字的关系有以下两种情况: 1).两行的数...

2019-10-21 21:43:18 273

原创 leetcode-1182-与目标颜色间的最短距离

题目链接在这里:https://leetcode-cn.com/problems/shortest-distance-to-target-color/ 题目大意 给你一个数组 colors,里面有 1、2、 3 三种颜色。 我们需要在 colors 上进行一些查询操作 queries,其中每个待查项都由两个整数 i 和 c 组成。 现在请你帮忙设计一个算法,查找从索引 i 到具有目标颜色 c 的...

2019-10-21 02:24:10 375

原创 迭代器 iterator

迭代器有时又称为游标,是程序设计的软件设计模式,可在容器上遍历的接口,设计人人员无需关心容器的内容。 迭代器是一种对象,它能够用来遍历标准模板库容器中的部分或者全部的元素,每个迭代器对象代表容器中的确定的地址。迭代器修改了常规指针的接口,所谓迭代器是一种概念上的抽象;那些行为上像迭代器的东西都可以叫做迭代器,然而迭代器又很多不同的能力,它可以把抽象容器和通用算法有机的统一起来。 ...

2019-10-21 01:35:21 152

原创 Leetcode clone-graph 克隆图

题目描述 图的遍历方法有两种:深度优先和广度优先。 解法一:深度优先搜索 用一个哈希表hashMap来记录已经克隆了的节点,深度优先遍历的递归函数实现如下: (1)如果node节点本身为null,直接返回null。 (2)如果hashMap中已经存在了node.label对应的节点,直接返回该节点即可。 (3)如果hashMap中还没有存在node.label对应的节点,新建一个节点,其labe...

2019-03-21 13:58:05 186

原创 Leetcode Gas Station(加油站)

Leetcode Gas Station题目描述思路代码 题目描述 在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升。 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。 如果你可以绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。 思路 我们首先要知道能走完整个...

2019-03-20 23:28:40 155

转载 1~n中1出现的次数《剑指offer》

转载自:从1到n整数中1出现的次数:O(logn)算法 1. 解题思路 考虑将n的十进制的每一位单独拿出讨论,每一位的值记为weight。 1) 个位 从1到n,每增加1,weight就会加1,当weight加到9时,再加1又会回到0重新开始。那么weight从0-9的这种周期会出现多少次呢?这取决于n的高位是多少,看图: 以534为例,在从1增长到n的过程中,534的个位从0-9...

2019-03-18 18:59:30 163

转载 single-number-ii leetcode

Given an array of integers, every element appearsthreetimes except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ...

2019-03-13 23:12:17 81

原创 次数出现为1的数

题目描述 有一组存放 ID 的数据。并且 ID 取值为 0 - (N-1) 之间,其中只有一个 ID 出现的次数为 1,其他的 ID 出现的次数都等于 2,问如何找到这个次数为 1 的 ID ? 解法一:巧用数组下标 我的第一想法便是采用下标法来解决,把 ID 作为数组 arr 的下标,在遍历 ID 的过程中,用数组记下每个 ID 出现的次数,即每次遍历到 ID = n,则 arr[n]++...

2019-03-13 22:32:06 338

原创 windows下修改pip镜像源

一、在windows环境下修改pip镜像源的方法(以python3.5为例) (1):在windows文件管理器中,输入 %APPDATA% (2):会定位到一个新的目录下,在该目录下新建pip文件夹,然后到pip文件夹里面去新建个pip.ini文件 (3):在新建的pip.ini文件中输入以下内容,搞定文件路径:"C:\Users\Administrator\AppData\Roaming...

2019-01-21 21:34:33 149

原创 if __name__=='__main__' 含义

在python中__name__是当前模块名,当模块被直接运行时模块名为__main__,类似于C语言中的__LINE__之类的用法。这句话的含义是当模块直接被运行的时候,以下代码块将被运行,当模块被import的时候,代码块不运行。 这段代码的功能 一个python文件的使用方式有两种,第一是直接作为脚本执行,第二是import'到其他的python脚本中被调用(模块重用)执行。因此if _...

2019-01-21 11:47:56 1727 1

原创 Leetcode copy list with random pointer 拷贝带有随机指针的链表

题目描述 A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 题目大意:给定一个链表,每个节点包含一个另外的随机的指...

2018-10-29 23:38:41 107

原创 Leetcode word break ii 单词拆分

题目描述 Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens ="c...

2018-10-27 19:58:14 132

原创 Leetcode word break 分词造句

题目描述 Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens ="leetcode",dict =["leet", ...

2018-10-25 12:19:28 507 1

原创 Leetcode linked-list-cycle 判断链表是否有环

题目描述   Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 给定一个链表,判断链表中否有环。 补充:         你是否可以不用额外空间解决此题? 思路:使用快慢指针,如果快指针和慢指针可以相遇,则证明该链表...

2018-10-23 17:52:01 175

原创 Leetcode linked-list-cycle-ii 判断链表存在环

题目描述   Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up: Can you solve it without using extra space? 给定一个链表,返回环开始的结点,如果没有环存在则返回NULL。 接着: 能...

2018-10-23 17:34:57 169

原创 Leetcode reorder-list 链表重排序

题目描述   Given a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You must do this in-place without altering the nodes' values. For example, Given{1,2,3,4}, r...

2018-10-23 16:45:30 125

原创 Leetcode binary-tree-preorder- traversal 二叉树的前序遍历 Java

题目描述   Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3   return[1,2,3]. Note: Recursive solution...

2018-10-23 11:59:42 156

原创 Leetcode binary-tree-postorder 二叉树后续遍历

题目描述   Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3   return[3,2,1]. Note: Recursive solutio...

2018-10-19 20:32:35 98

原创 Leetcode insertion-sort-list 插入排序 Java

题目描述   Sort a linked list using insertion sort. 对链表进行插入排序 题目解析 插入排序的方法是首先构造出一个与head值相同的结点res,比较该结点的值和head后面结点cur的值,若小于head,则cur指向 res,res赋值为cur。否则将cur插入到res后面的结点中。 代码如下 /** * Definition for ...

2018-10-19 17:37:10 185

原创 LeetCode Sort-List Java

题目描述   Sort a linked list in O(n log n) time using constant space complexity. 题目解析 归并排序,使用fast和slow指针的方式来将链表一分为二。 /** * Definition for singly-linked list. * class ListNode { * int val; *...

2018-10-19 16:59:15 121

原创 LeetCode:max-points-on-a-line(位于一条线上的点的最大个数)Java实现

题目描述   Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 给定二维平面上的n个点,请你找出位于一条直线上的点的最大个数。 题目解析 暴力求解: 使用两层循环,注意第二层循环里面考虑相同的点,使用变量same来进行保存。在第二层循环中...

2018-10-19 15:06:03 229

原创 evaluate-reverse-polish-notation(逆波兰表达式的值的计算)

题目描述   Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are+,-,*,/. Each operand may be an integer or another expression. Some examples: ["2", "1", "+...

2018-10-19 14:08:30 200

原创 mininum-depth-of-binary-tree

题目描述 Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 该题目的解法就是寻找离根结点最近的叶子节点 解法1(递归):Jav...

2018-10-18 17:28:39 208

Java开发从入门带精通源代码

Java开发从入门到精通一书的配套源代码,是所有的源代码,每个章节都有

2017-10-15

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除