├── .gitignore
├── .idea
└── vcs.xml
├── 018429.c
├── 2018.11.15
├── 1.md
├── 2.md
├── demo1.md
├── wc.md
└── 暮成雪.md
├── 2018.11.16
└── 1.md
├── 2018.11.17
└── 1.md
├── 2018.11.18
├── 1.md
└── 大腩肚.md
├── 2018.11.19-leetcode15
├── Felix.md
├── Istoryforever.md
├── Ostrichcrab.md
└── 棕榈树.md
├── 2018.11.19
└── 1.md
├── 2018.11.20
└── 1.md
├── 2018.11.21
└── 1.md
├── 2018.11.22
└── 1.md
├── 2018.11.24-leetcode28
├── ELF
├── TheRocket
├── Tony the Cyclist.md
├── WhiteNight.md
├── Whits.md
├── kiritocly
├── sourcema.md
├── syuan.md
├── syuan1.md
├── 乔戈里.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 张小胖.md
├── 超能炸弹人.md
└── 雪辰.markdown
├── 2018.11.25-leetcode80
├── Be a fresh man.md
├── Felix.md
├── Istoryforever.md
├── Ostrichcrab.md
├── Sagittarius.md
├── Tony the Cyclist.md
├── caroline.md
├── disappo1nted.md
├── kiritocly.md
├── sourcema.md
├── str818.md
├── syuan.md
├── 乔戈里.md
├── 句子.md
├── 大王
├── 大魔王爱穿孖烟筒.md
├── 张小胖.md
├── 忆季落花.md
├── 湛江甲鸟.md
└── 黎明初醒.md
├── 2018.11.26-leetcode11
├── ChenforCode.md
├── FFFro.md
├── Istoryforever.md
├── MQQM.cpp
├── MQQM2.cpp
├── Ostrichcrab.md
├── PJ.md
├── TheRocket.md
├── Tony the Cyclist.md
├── Valor Dawn.md
├── halfofwater.md
├── kiritocly.md
├── sourcema.md
├── str818.md
├── syuan.md
├── tongLuoWan.md
├── zjukk.md
├── 。。。.md
├── 乔戈里.md
├── 句子.md
├── 大魔王爱穿孖烟筒.md
├── 家.md
├── 暮成雪.md
├── 神秘的火柴人.md
├── 种花家的鄂兔.md
├── 程群quanycheng
├── 雷金.md
└── 黎明初醒.md
├── 2018.11.27-leetcode125
├── Avalon.md
├── Be a fresh man.md
├── ChenforCode.md
├── FFFro.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WhiteNight.md
├── caroline.md
├── cuiHlu.md
├── halfofwater.md
├── kiritocly.md
├── sourcema.md
├── str818.md
├── tongLuoWan.md
├── zjukk.md
├── 。。。.md
├── 刘润泽.md
├── 句子.java
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 孙行者.md
├── 家.md
├── 我爱吃瓜子.md
├── 暮成雪.md
├── 棕榈树.md
├── 湛江甲鸟.md
├── 神秘的火柴人.md
├── 铁男神sama.java
└── 铁男神sama.md
├── 2018.11.28
├── 2018.11.28-leetcode151
├── -.md
├── 018429.md
├── Avalon.md
├── Be a fresh man.md
├── FFFro.md
├── GatesMa.md
├── Istoryforever.md
├── Ostrichcrab.md
├── Sagittarius.md
├── TheRocket.md
├── Tony the Cyclist.md
├── V1ncentzzZ
├── WhiteNight.md
├── cuiHlu.md
├── disappo1nted.md
├── halfodfwater.md
├── ieei.md
├── kiritocly.md
├── oven123.md
├── sourcema.md
├── str818.md
├── syuan.md
├── zjukk.md
├── 。。。.md
├── 不能吃太饱.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 小熊君.md
├── 张小胖.md
├── 我爱吃瓜子.md
├── 晨曦雨露.md
├── 杨.md
├── 棕榈树.md
├── 湛江甲鸟.md
├── 神秘的火柴人.md
├── 空白.md
└── 铁男神sama.md
├── 2018.11.29-leetcode443
├── -.md
├── Avalon.md
├── Be a fresh man.md
├── Decadence.md
├── FFFro.md
├── GatesMa.md
├── Icy.md
├── Istoryforever.md
├── Mr.Q.md
├── Ostrichcrab.md
├── Sagittarius.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WhiteNight.md
├── halfofwater.md
├── kiritocly.md
├── oven123.md
├── sourcema.md
├── str818.md
├── syuan.md
├── zjukk.md
├── 、Mr。oh!.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 一氧化二钒.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 张小胖.md
├── 我爱吃瓜子.md
├── 杨.md
├── 湛江甲鸟.md
└── 神秘的火柴人.md
├── 2018.11.30-leetcode890
├── -.md
├── Avalon.md
├── Be a fresh man.md
├── GatesMa.md
├── Istoryforever.md
├── Ostrichcrab.md
├── Sagittarius.md
├── Sagittatius.md
├── Saul.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── kiritocly.md
├── sourcema.md
├── suecurry.md
├── syuan.md
├── zjukk.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 刘润泽.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 家
├── 张小胖.md
├── 我爱吃瓜子
├── 李碧涵.md
├── 神秘的火柴人.md
└── 铁男神sama.md
├── 2018.12.04-leetcode101
├── Avalon.md
├── Be a fresh man.md
├── Despacito.md
├── Istoryforever.md
├── MQQM.cpp
├── Saul.md
├── Tony the Cyclist.md
├── WhiteNight.md
├── fish.md
├── kiritocly.md
├── marguerite.md
├── sourcema.md
├── syuan.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 李碧涵.md
├── 杨.md
├── 湛江甲鸟.md
├── 神秘的火柴人.md
├── 铁男神sama.md
└── 阳.md
├── 2018.12.05-leetcode102
├── -.md
├── Avalon.md
├── Be a fresh man.md
├── Despacito.md
├── FFFro.md
├── Felix.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WhiteNight.md
├── kaizen
├── marguerite.md
├── sourcema.md
├── syuan.md
├── zjukk.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 二叉树的层次遍历.md
├── 利爪德鲁伊.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 李碧涵.md
├── 棕榈树.md
├── 神秘的火柴人.md
├── 莎莎.md
├── 铁男神sama.md
└── 阳.md
├── 2018.12.06-leetcode103
├── -.md
├── 103. 二叉树的锯齿形层次遍历.md
├── Avalon.md
├── Be a fresh man.md
├── Despacito.md
├── FFFro.md
├── Felix.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── Typing.txt
├── WhiteNight.md
├── sourcema.md
├── syuan.md
├── zjukk.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 利爪德鲁伊.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 李碧涵.md
├── 神秘的火柴人.md
├── 莎莎.md
└── 铁男神sama.md
├── 2018.12.07-leetcode104
├── -.md
├── 104. 二叉树的最大深度
├── Avalon.md
├── Be a fresh man.md
├── Despacito.md
├── FFFro.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Saul.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── Typing.txt
├── WhiteNight.md
├── disappo1nted.md
├── fish.md
├── justwe.md
├── sourcema.md
├── syuan.md
├── zjukk.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 利爪德鲁伊.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 张小胖.md
├── 李碧涵.md
├── 棕榈树.md
├── 神秘的火柴人.md
├── 莎莎.md
├── 铁男神sama.md
└── 阳.md
├── 2018.12.08-leetcode105
├── -.md
├── 105. 从前序与中序遍历序列构造二叉树.md
├── Avalon.md
├── Be a fresh man.md
├── Despacito.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── Typing.txt
├── WhiteNight.md
├── fish.md
├── sourcema.md
├── syuan.md
├── zjukk.md
├── 利爪德鲁伊.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 李碧涵.md
├── 神秘的火柴人.md
├── 莎莎.md
└── 阳.md
├── 2018.12.09-leetcode106
├── -.md
├── 106. 从中序与后序遍历序列构造二叉树.md
├── Avalon.md
├── Be a fresh man.md
├── Despacito.md
├── FFFro.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── Typing.txt
├── WhiteNight.md
├── fish.md
├── marguerite.md
├── sourcema.md
├── zjukk.md
├── 啦啦啦.md
├── 妮可.md
├── 李碧涵.md
├── 神秘的火柴人.md
└── 莎莎.md
├── 2018.12.1-leetcode387
├── -.md
├── Avalon.md
├── Be a fresh man.md
├── FFFro.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── MQQM2.cpp
├── MQQM3.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Saul.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WhiteNight.md
├── halfofwater.md
├── justwe.md
├── kiritocly.md
├── sourcema.md
├── syuan.md
├── zjukk.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 云深不叹.md
├── 云胡不喜.md
├── 大魔王爱穿孖烟筒.md
├── 家
├── 张小胖.md
├── 我的微信名是空格.md
├── 李碧涵.md
├── 杨.md
├── 湛江甲鸟.md
├── 神秘的火柴人.md
├── 莎莎.md
├── 莫少侠.md
├── 铁男神sama.md
├── 阳.md
├── 雪辰.md
├── 雷金.md
├── 青衫忆笙.md
└── 飞狐.md
├── 2018.12.10-leetcode107
├── 1.md
├── 2.md
├── Avalon.md
├── Be a fresh man.md
├── Despacito.md
├── FFFro.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── MQQM2.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WhiteNight.md
├── fish.md
├── marguerite.md
├── sourcema.md
├── syuan.md
├── 利爪德鲁伊.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 张小胖.md
├── 李碧涵.md
├── 神秘的火柴人.md
├── 莎莎.md
└── 阳.md
├── 2018.12.11-leetcode108
├── 108. 将有序数组转换为二叉搜索树.md
├── Avalon.md
├── Be a fresh man.md
├── FFFro.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── WhiteNight.md
├── marguerite.md
├── sourcema.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 李碧涵.md
├── 棕榈树.md
├── 神秘的火柴人.md
└── 莎莎.md
├── 2018.12.12-leetcode109
├── 109. 有序链表转换二叉搜索树
├── Avalon.md
├── Be a fresh man.md
├── FFFro.md
├── GatesMa.md
├── Istoryforever.md
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 李碧涵.md
├── 棕榈树.md
└── 神秘的火柴人.md
├── 2018.12.13-leetcode215
├── 123456.md
├── 215. 数组中的第K个最大元素
├── Avalon.md
├── Be a fresh man.md
├── GatesMa.md
├── Istoryforever.md
├── MQQM.cpp
├── MQQM2.cpp
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── Typing.txt
├── WYJ.md
├── sourcema.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 妮可.md
├── 李碧涵.md
├── 神秘的火柴人.md
└── 阳.md
├── 2018.12.14-leetcode347
├── 123456.md
├── 347. 前K个高频元素
├── Avalon.md
├── Be a fresh man.md
├── Istoryforever.md
├── MQQM.cpp
├── Ostrichcrab.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── sourcema.md
├── 妮可.md
├── 李碧涵.md
└── 神秘的火柴人.md
├── 2018.12.15-leetcode451
├── 123456.md
├── 451. 根据字符出现频率排序
├── Avalon.md
├── Be a fresh man.md
├── Istoryforever.md
├── Ostrichcrab.md
├── Sagittarius.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── sourcema.md
├── 妮可.md
├── 李碧涵.md
├── 棕榈树.md
└── 神秘的火柴人.md
├── 2018.12.16-leetcode75
├── 75. 颜色分类
├── Avalon.md
├── Be a fresh man.md
├── Istoryforever.md
├── Ostrichcrab.md
├── Sagittarius.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── WhiteNight.md
├── XXXX.md
├── sourcema.md
├── 妮可.md
├── 李碧涵.md
└── 神秘的火柴人.md
├── 2018.12.17-leetcode445
├── Avalon.md
├── Ostrichcrab.md
├── oven123.md
├── sourcema.md
├── 嗯.md
├── 李碧涵.md
├── 棕榈树.md
└── 神秘的火柴人.md
├── 2018.12.17-leetcode455
├── 455. 分发饼干.md
├── Avalon.md
├── Be a fresh man.md
├── TheRocket.md
├── sourcema.md
├── 刘润泽(capture).md
├── 妮可.md
├── 李碧涵.md
└── 神秘的火柴人.md
├── 2018.12.18-leetcode435
├── 435. 无重叠区间.md
├── Avalon.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 妮可.md
├── 李碧涵.md
└── 神秘的火柴人.md
├── 2018.12.19-leetcode452
├── 452. 用最少数量的箭引爆气球.md
├── Avalon.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 妮可.md
├── 李碧涵.md
├── 棕榈树.md
└── 神秘的火柴人.md
├── 2018.12.2-leetcode557
├── -.md
├── 123456 122
├── 123456.md
├── 557. 反转字符串中的单词 III
├── 557.txt
├── Avalon.md
├── Be a fresh man.md
├── GatesMa.md
├── HCL6666HCL.md
├── Istoryforever.md
├── Ostrichcrab.md
├── Sagittarius.md
├── Saul.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── disappo1nted.md
├── halfofwater.md
├── kiritocly.md
├── sourcema.md
├── syuan.md
├── wangli_eic
├── zjukk.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 云深不叹.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 我爱吃瓜子.md
├── 李碧涵.md
├── 杨jia.md
├── 棕榈树(表情).md
├── 湛江甲鸟.md
├── 神秘的火柴人.md
├── 莎莎.md
├── 莫少侠、反正字符串3
├── 雷金.md
└── 青衫忆笙.md
├── 2018.12.2-leetcode557_远方
├── 2018.12.20-leetcode406
├── 406. 根据身高重建队列.md
├── Avalon.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── Sagittarius.md
├── TheRocket.md
├── marguerite.md
├── sourcema.md
├── 李碧涵.md
├── 棕榈树.md
└── 神秘的火柴人.md
├── 2018.12.21-leetcode763
├── 763. 划分字母区间.md
├── Avalon.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── WYJ.md
├── sourcema.md
├── 李碧涵.md
└── 棕榈树.md
├── 2018.12.22-leetcode605
├── 605. 种花问题.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── sourcema.md
├── 张小胖.md
├── 李碧涵.md
└── 棕榈树.md
├── 2018.12.23-leetcode392
├── 392. 判断子序列.md
├── Be a fresh man.md
├── FFFro.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── lyan_dut.md
├── sourcema.md
└── 李碧涵.md
├── 2018.12.24-leetcode665
├── 665. 非递减数列.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── sourcema.md
├── 利爪德鲁伊.md
├── 妮可.md
└── 李碧涵.md
├── 2018.12.25-leetcode122
├── 122. 买卖股票的最佳时机 II.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 刘润泽(capture).md
├── 利爪德鲁伊.md
├── 句子.md
├── 妮可.md
├── 李碧涵.md
└── 棕榈树.md
├── 2018.12.26-leetcode53
├── 53. 最大子序和.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 刘润泽(capture).md
├── 利爪德鲁伊.md
├── 妮可.md
├── 李碧涵.md
└── 棕榈树.md
├── 2018.12.27-leetcode121
├── 121. 买卖股票的最佳时机.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 刘润泽(capture).md
├── 利爪德鲁伊.md
├── 妮可.md
└── 李碧涵.md
├── 2018.12.28-leetcode69
├── 69. x 的平方根.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── sourcema.md
├── 利爪德鲁伊.md
├── 妮可.md
└── 李碧涵.md
├── 2018.12.29-leetcode744
├── 744. 寻找比目标字母大的最小字母.md
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── YYT.md
├── sourcema.md
├── 利爪德鲁伊.md
├── 妮可.md
├── 李碧涵.md
└── 棕榈树.md
├── 2018.12.3-leetcode58
├── -.md
├── Avalon.md
├── Be a fresh man.md
├── FFFro.md
├── Felix.md
├── GatesMa.md
├── Istroyforever.md
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WhiteNight.md
├── disappo1nted.md
├── fish.md
├── halfofwater.md
├── kiritocly.md
├── marguerite.md
├── sourcema.md
├── syuan.md
├── tongLuoWan.md
├── zjukk.md
├── 。V1ncentzzZ.md
├── 。。。.md
├── 云深不叹.md
├── 啦啦啦.md
├── 大魔王爱穿孖烟筒.md
├── 家
├── 张小胖.md
├── 我爱吃瓜子.md
├── 最后一个单词的长度.md
├── 李碧涵.md
├── 杨.md
├── 湛江甲鸟.md
├── 神秘的火柴人.md
├── 莎莎.md
├── 阳.md
├── 青衫忆笙.md
└── 黎明初醒.md
├── 2018.12.30-leetcode540
├── 540. 有序数组中的单一元素.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── lyan_dut.md
├── sourcema.md
├── 刘润泽(capture).md
├── 妮可.md
├── 李碧涵.md
└── 棕榈树.md
├── 2018.12.31-leetcode278
├── 278.第一个错误的版本.md
├── Ostrichcrab.md
├── TheRocket.md
├── WYJ.md
├── sourcema.md
└── 李碧涵.md
├── 2018.12.4-leetcode101
├── -.md
├── 1.md
├── FFFro.md
├── GatesMa.md
├── Ostrichcrab.md
├── Sagittarius.md
├── Sunny.md
├── TheRocket.md
├── halfofwater.md
├── linyk3.md
├── oven123.md
├── zjukk.md
├── 。。。.md
├── 云溪101.md
├── 利爪德鲁伊.md
├── 啦啦啦.md
├── 家.md
├── 张小胖.md
└── 莎莎.md
├── 2019.01.01-leetcode153
├── 153.旋转数组的最小数字.md
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 李碧涵.md
└── 神秘的火柴人.md
├── 2019.01.02-leetcode34
├── Ostrichcrab.md
├── TheRocket.md
├── Tony the Cyclist.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 刘润泽(capture).md
├── 在排序数组中查找元素的第一个和最后一个位置.md
├── 李碧涵.md
└── 神秘的火柴人.md
├── 2019.01.03-leetcode241
├── Ostrichcrab.md
├── TheRocket.md
├── marguerite.md
├── sourcema.md
├── 为运算表达式设计优先级
├── 刘润泽(capture).md
└── 李碧涵.md
├── 2019.01.04-leetcode279
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 完全平方数
├── 李碧涵.md
└── 神秘的火柴人.md
├── 2019.01.05-leetcode127
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 单词接龙
└── 神秘的火柴人.md
├── 2019.01.06-leetcode695
├── Ostrichcrab.md
├── TheRocket.md
├── WYJ.md
├── sourcema.md
├── 岛屿的最大面积
└── 神秘的火柴人.md
├── 2019.01.07-leetcode200
├── TheRocket.md
├── marguerite.md
├── sourcema.md
├── 刘润泽(capture).md
└── 岛屿的个数
├── 2019.01.08-leetcode547
├── TheRocket.md
├── margueriete.md
├── sourcema.md
├── 刘润泽(capture).md
├── 朋友圈
└── 棕榈树.md
├── 2019.01.09-leetcode130
├── Be a fresh man.md
├── Ostrichcrab.md
├── TheRocket.md
├── 刘润泽(capture).md
├── 棕榈树.md
└── 被围绕的区域
├── 2019.01.10-leetcode417
├── Ostrichcrab.md
├── TheRocket.md
├── marguerite.md
├── sourcema.md
├── 刘润泽(capture).md
├── 太平洋大西洋水流问题
└── 棕榈树.md
├── 2019.01.11-leetcode17
├── Ostrichcrab.md
├── TheRocket.md
├── WYJ.md
├── sourcema.md
├── 刘润泽(capture).md
├── 棕榈树.md
└── 电话号码的字母组合
├── 2019.01.12-leetcode93
├── Ostrichcrab.md
├── TheRocket.md
├── WYJ.md
├── marguerite.md
├── sourcema.md
├── 刘润泽(capture).md
├── 复原IP地址
└── 棕榈树.md
├── 2019.01.13-leetcode79
├── Ostrichcrab.md
├── TheRocket.md
├── WYJ.md
├── sourcema.md
├── 刘润泽(capture).md
├── 单词搜索
└── 棕榈树.md
├── 2019.01.14-leetcode257
├── Ostrichcrab.md
├── TheRocket.md
├── marguerite.md
├── sourcema.md
├── 二叉树的所有路径
├── 刘润泽(capture).md
└── 棕榈树.md
├── 2019.01.15-leetcode46
├── Ostrichctab.md
├── TheRocket.md
├── marguerite.md
├── 全排列
├── 刘润泽(capture).md
└── 棕榈树.md
├── 2019.01.16-leetcode47
├── Ostrichcrab.md
├── TheRocket.md
├── marguerite.md
├── 全排列II
└── 刘润泽(capture).md
├── 2019.01.17-leetcode77
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 刘润泽(capture).md
├── 棕榈树.md
└── 组合
├── 2019.01.18-leetcode39
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 刘润泽(capture).md
├── 棕榈树.md
└── 组合总和
├── 2019.01.19-leetcode40
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 刘润泽(capture).md
├── 棕榈树.md
└── 组合总和II
├── 2019.01.20-leetcode216
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 刘润泽(capture).md
├── 棕榈树.md
└── 组合总和III
├── 2019.01.21-leetcode78
├── Ostrichcrab.md
├── TheRocket.md
├── marguerite.md
├── sourcema.md
├── 刘润泽(capture).md
├── 子集
└── 棕榈树.md
├── 2019.01.22-leetcode90
├── Ostrichcrab.md
├── TheRocket.md
├── marguerite.md
├── 子集II
└── 棕榈树.md
├── 2019.01.23-leetcode131
├── Ostrichcrab.md
├── TheRocket.md
├── marguerite.md
├── sourcema.md
└── 分割回文串
├── 2019.01.24-leetcode37
├── Ostrichcrab.md
├── TheRocket.md
├── 刘润泽(capture).md
├── 棕榈树.md
└── 解数独
├── 2019.01.25-leetcode51
├── N皇后
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
└── 棕榈树.md
├── 2019.01.26-leetcode70
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 棕榈树.md
└── 爬楼梯
├── 2019.01.27-leetcode198
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 打家劫舍
└── 棕榈树.md
├── 2019.01.28-leetcode213
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
└── 打家劫舍II
├── 2019.01.29-leetcode64
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 最小路径和
└── 棕榈树.md
├── 2019.01.30-leetcode62
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 不同路径
└── 棕榈树.md
├── 2019.01.31-leetcode303
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 区域和检索-数组不可变
└── 棕榈树.md
├── 2019.02.01-leetcode413
├── Ostrichcrab.md
├── TheRocket.md
├── sourcema.md
├── 棕榈树.md
└── 等差数列划分
├── 2019.02.02-leetcode343
├── Ostrichcrab.md
├── TheRocket.md
├── 整数拆分
└── 棕榈树.md
├── 2019.02.03-leetocde279
├── Ostrichcrab.md
├── TheRocket.md
├── 完全平方数
└── 棕榈树.md
├── 2019.02.09-leetcode91
├── TheRocket.md
└── 解码方法
├── 2019.02.10-leetcode300
├── TheRocket.md
└── 最长上升子序列
├── 2019.02.11-leetcode646
├── TheRocket.md
├── jackykun2012.md
└── 最长数对链
├── 2019.02.12-leetcode376
├── TheRocket.md
└── 摆动序列
├── 2019.02.13-leetcode416
├── TheRocket.md
└── 分割等和子集
├── 2019.02.14-leetcode494
├── TheRocket.md
└── 目标和
├── 2019.02.15-leetcode139
├── TheRocket.md
└── 单词拆分
├── 2019.02.16-leetcode474
├── TheRocket.md
└── 一和零
├── 2019.02.17-leetcode322
├── Sagittarius.md
├── TheRocket.md
└── 零钱兑换
├── 2019.02.18-leetcode377
├── TheRocket.md
└── 组合总和IV
├── 2019.02.19-leetcode309
├── TheRocket.md
└── 最佳买卖股票时机含冷冻期
├── 2019.02.20-leetcode714
├── TheRocket.md
└── 买卖股票的最佳时机含手续费
├── 2019.02.21-leetcode123
└── 买卖股票的最佳时机III
├── 2019.02.22-leetcode188
└── 买卖股票的最佳时机IV
├── 2019.02.23-leetcode583
└── 两个字符串的删除操作
├── 2019.02.24-leetcode72
└── 编辑距离
├── README.md
├── Sagittarius.md
├── Selfcenter.md
├── fish.md
├── leetcode203
├── Be a fresh man.md
├── Ostrichcrab.md
└── 家.md
├── notKnow
├── OCEAN_he95.md
├── 句子.md
└── 大魔王爱穿孖烟筒.md
├── zjukk.md
├── 妮可.md
├── 蓝星尘.java
└── 青衫忆笙.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | */.DS_Store
3 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/018429.c:
--------------------------------------------------------------------------------
1 | int firstUniqChar(char* s) {
2 | int ascii[256]={0};
3 | int i=0,len;
4 | while(s[i]!='\0')
5 | {
6 | i++;
7 | }
8 | len=i;
9 | for(i=0;i& height) {
6 | int height_len = height.size();
7 | int start = 0;
8 | int end = height_len - 1;
9 | int max_area = 0;
10 | while( start < end ){
11 | max_area = max(max_area, min(height[start], height[end]) * (end - start));
12 | //更新 start 和 end
13 | if(height[start] < height[end])
14 | start++;
15 | else end--;
16 | }
17 | return max_area;
18 | }
19 | };
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/Istoryforever.md:
--------------------------------------------------------------------------------
1 | leetcode number 80
2 | ```
3 | class Solution {
4 | public:
5 | void swap(int &a,int &b){
6 | int c = a;
7 | a = b;
8 | b = a;
9 |
10 | }
11 | int removeDuplicates(vector& nums) {
12 | int j = -1;
13 | int count = 0;
14 | for(int i = 0;i < nums.size();i++){
15 | if(i != 0 && nums[i] == nums[i-1]) {
16 | if(count >= 1) continue;
17 | ++count;
18 | }
19 | else
20 | count = 0;
21 | nums[++j]=nums[i];
22 | }
23 | return j+1;
24 |
25 | }
26 | };
27 | ```
28 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```
2 |
3 | class Solution {
4 | public int removeDuplicates(int[] nums) {
5 | if (nums.length < 3){
6 | return nums.length;
7 | }
8 | int pos = 2;
9 | for(int i = 2; i < nums.length; i++){
10 | if(nums[i]!=nums[pos-2])
11 | nums[pos++]=nums[i];
12 | }
13 | return pos;
14 | }
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/caroline.md:
--------------------------------------------------------------------------------
1 |
2 | caroline.md
3 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/disappo1nted.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | int index = 0;
3 | int j = 1;
4 | int i = 0;
5 |
6 | public int removeDuplicates(int[] nums) {
7 | while(i <= nums.length - 1) {
8 | if(j < nums.length && nums[i] == nums[j]) {
9 | if(j - i == 1) {
10 | nums[index++] = nums[i];
11 | }
12 | j++;
13 | }
14 | else {
15 | nums[index++] = nums[j - 1];
16 | i = j;
17 | j++;
18 | }
19 | }
20 | return index;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/sourcema.md:
--------------------------------------------------------------------------------
1 | # leetcode 80
2 | public int removeDuplicates(int[] nums) {
3 | if (nums == null || nums.length == 0 || nums.length < 3) {
4 | return nums.length;
5 | }
6 | int i=0;
7 | for (int j = 0; j < nums.length; j++) {
8 | if (i < 2 || nums[j] != nums[i - 2]) {
9 | nums[i] = nums[j];
10 | i++;
11 | }
12 | }
13 | return i;
14 | }
15 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/str818.md:
--------------------------------------------------------------------------------
1 | # 删除排序数组中的重复项 Ⅱ
2 |
3 | **解题思路:** 遍历一遍数组,用一个下标记录替换位置,将所有元素重新赋值一遍。
4 | ```java
5 | public int removeDuplicates(int[] nums) {
6 | if(nums == null || nums.length == 0) return 0;
7 |
8 | int i = 0;
9 | for(int num : nums){
10 | if(i < 2 || num > nums[i-2]){
11 | nums[i] = num;
12 | i += 1;
13 | }
14 | }
15 | return i;
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/句子.md:
--------------------------------------------------------------------------------
1 | ```
2 | public class FOR80 {
3 | public static int removeDuplicates(int[] nums) {
4 | if (nums.length < 3)
5 | return nums.length;
6 | int j = 2;
7 | int last = nums[1], d_last = nums[0];
8 | for (int i = 2; i < nums.length; ++i) {
9 | if (d_last == last && d_last == nums[i])
10 | continue;
11 | nums[j++]=nums[i];
12 | d_last=last;
13 | last=nums[0];
14 | }
15 | return j;
16 | }
17 | public static void main(String[] args) {
18 |
19 | }
20 | }
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/大王:
--------------------------------------------------------------------------------
1 | 测试leetcode提交
2 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/张小胖.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | int removeDuplicates(vector& nums) {
4 | if (nums.size() <= 2) return nums.size();
5 | int end = 2; //end是最终的长度
6 | for (int i = 2; i < nums.size(); i++) {
7 | if (nums[end - 2] != nums[i]) { //对比这两个数是否相等即可
8 | nums[end++] = nums[i];
9 | }
10 | }
11 | return end;
12 | }
13 | };
14 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/忆季落花.md:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | class Solution:
3 | def __init__(self):
4 | self.stack1=[]
5 | self.stack2=[]
6 | def push(self, node):
7 | self.stack1.append(node)
8 | def pop(self):
9 | if self.stack2:
10 | return self.stack2.pop()
11 | else:
12 | while self.stack1:
13 | self.stack2.append(self.stack1.pop())
14 | return self.stack2.pop()
15 | # return xx
16 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/湛江甲鸟.md:
--------------------------------------------------------------------------------
1 | ```
2 | public int maxArea(int[] height) {
3 | int maxArea = 0;
4 | int left = 0;
5 | int right = height.length - 1;
6 | while (left < right) {
7 | // 下面一行代码循环开头是因为当出现right = 2,即 输入的数组只有2个非负整数的情况可以直接计算并返回结果
8 | maxArea = Math.max(maxArea, Math.min(height[left], height[right]) * (right - left));
9 | if (height[left] <= height[right]) {
10 | left++;
11 | } else {
12 | right--;
13 | }
14 |
15 | // maxArea = Math.max(maxArea, Math.min(height[left], height[right]) * (right - left));
16 | }
17 | return maxArea;
18 | }
19 |
--------------------------------------------------------------------------------
/2018.11.25-leetcode80/黎明初醒.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int removeDuplicates(int[] nums) {
4 | if(nums.length==0){
5 | return 0;
6 | }
7 | int count = 0;
8 | int j = 0;
9 | for(int i=1;ib?a:b;}
5 | int min(int a, int b){return a& height) {
7 | int ans = 0;
8 | int l = 0, r = height.size() - 1;
9 | ans = max(ans,min(height[l],height[r])*(r-l));
10 | while(lheight[r]){
12 | r--;
13 | ans = max(ans,min(height[l],height[r])*(r-l));
14 | }else{
15 | l++;
16 | ans = max(ans,min(height[l],height[r])*(r-l));
17 | }
18 | }
19 | return ans;
20 | }
21 | };
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/PJ.md:
--------------------------------------------------------------------------------
1 | public static void main(String[] args) {
2 | System.out.printIn("test");
3 | }
4 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxArea(int[] height) {
4 | int i = 0;
5 | int j = height.length - 1;
6 | int res = 0;
7 | while (i < j) {
8 | int area = (j - i) * Math.min(height[i], height[j]);
9 | res = Math.max(res, area);
10 | if (height[i] < height[j]) {
11 | ++i;
12 | } else {
13 | --j;
14 | }
15 | }
16 | return res;
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/sourcema.md:
--------------------------------------------------------------------------------
1 | # leetcode 11
2 | public int maxArea(int[] height) {
3 | if (height == null || height.length == 0) {
4 | return 0;
5 | }
6 | int left=0,right=height.length-1,result=0;
7 | while (left < right) {
8 | result = Math.max(result, Math.min(height[left], height[right]) * (right - left));
9 | if (height[left] <= height[right]) {
10 | left++;
11 | } else {
12 | right--;
13 | }
14 | }
15 | return result;
16 | }
17 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/tongLuoWan.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int maxArea(int[] height) {
4 | int i = 0, j = height.length-1;
5 | int result = 0;
6 | while(i < j){
7 | int h = Math.min(height[i], height[j]);
8 | result = Math.max(result, (j-i) * h);
9 | while (i < j && h == height[i]) ++i;
10 | while (i < j && h == height[j]) --j;
11 | }
12 | return result;
13 | }
14 | }
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/。。。.md:
--------------------------------------------------------------------------------
1 | public int maxArea(int[] height) {
2 | int left=0,right=height.length-1,area = 0;
3 | while (left < right){
4 | area = Math.max(area,(right-left)*Math.min(height[left],height[right]));
5 | if (height[left] < height[right]){
6 | left++;
7 | }else {
8 | right--;
9 | }
10 | }
11 | return area;
12 | }
13 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/家.md:
--------------------------------------------------------------------------------
1 | ```
2 | func maxArea(height []int) int {
3 | l := len(height)-1
4 | max,now := 0,0
5 | for a:=0;a= height[l] {
7 | now = height[l] * (l-a)
8 | l--
9 | }else {
10 | now = height[a] * (l-a)
11 | a++
12 | }
13 | if now > max {max = now}
14 | }
15 | return max
16 | }
17 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/神秘的火柴人.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | int maxArea(vector& height) {
4 | int l = 0;
5 | int r = height.size()-1;
6 |
7 | int container = 0;
8 | while(l < r)
9 | {
10 | int tmp = min(height[l], height[r]) * (r-l);
11 | container = max(tmp, container);
12 |
13 | l = (height[l] >= height[r])?l:r++;
14 | r = (height[l] < height[r])?r:r++;
15 | }
16 |
17 | return container;
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/雷金.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int maxArea(int[] height) {
4 | int i=0;
5 | int j = height.length-1;
6 | int area = 0;
7 | while(i=area?areas:area;
11 | }
12 | return area;
13 | }
14 | }
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.11.26-leetcode11/黎明初醒.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int maxArea(int[] height) {
4 | int i=0,j=height.length-1;
5 | int V=0,V1;
6 | while(i<=j) {
7 | if(height[i]<=height[j]) {
8 | V1 = (j-i)*height[i];
9 | i++;
10 | }
11 | else {
12 | V1 = (j-i)*height[j];
13 | j--;
14 | }
15 | if(V1>=V) {
16 | V = V1;
17 | }
18 |
19 | }
20 | return V;
21 | }
22 | }
23 | ```
24 |
--------------------------------------------------------------------------------
/2018.11.27-leetcode125/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 |
4 | public boolean isPalindrome(String s) {
5 | int i = 0;
6 | int j = s.length() - 1;
7 | while (i < j) {
8 | while (i < j && !Character.isLetterOrDigit(s.charAt(i))) {
9 | ++i;
10 | }
11 | while (i < j && !Character.isLetterOrDigit(s.charAt(j))) {
12 | --j;
13 | }
14 | if (Character.toLowerCase(s.charAt(i++)) != Character.toLowerCase(s.charAt(j--))) {
15 | return false;
16 | }
17 | }
18 | return true;
19 | }
20 | }
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.11.27-leetcode125/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public boolean isPalindrome(String s) {
4 | s = s.replaceAll("[ `~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~!@#¥%……&;*()\"——+|{}【】‘;:”“’。,、?|-]", "").toLowerCase();
5 | StringBuffer sb = new StringBuffer(s);
6 | return sb.toString().equals(sb.reverse().toString());
7 | }
8 | }
9 | ```
10 |
--------------------------------------------------------------------------------
/2018.11.27-leetcode125/cuiHlu.md:
--------------------------------------------------------------------------------
1 | //isalnum()判断是否为字母或者是数字
2 | bool isPalindrome(string s) {
3 | int length = s.size();
4 | int start = 0;
5 | int end = start + length - 1;
6 | while (start <= end)
7 | {
8 | if (!isalnum(s[start]))
9 | ++start;
10 | else if (!isalnum(s[end]))
11 | --end;
12 | else
13 | {
14 | if (tolower(s[start]) != tolower(s[end]))
15 | return false;
16 | ++start;
17 | --end;
18 | }
19 | }
20 | return true;
21 | }
22 |
--------------------------------------------------------------------------------
/2018.11.27-leetcode125/str818.md:
--------------------------------------------------------------------------------
1 | ```java
2 | public boolean isPalindrome(String s) {
3 | if (s.isEmpty()) return true;
4 | int head = 0, tail = s.length() - 1;
5 | char cHead, cTail;
6 | while(head <= tail) {
7 | cHead = s.charAt(head);
8 | cTail = s.charAt(tail);
9 | if (!Character.isLetterOrDigit(cHead)) {
10 | head++;
11 | } else if(!Character.isLetterOrDigit(cTail)) {
12 | tail--;
13 | } else {
14 | if (Character.toLowerCase(cHead) != Character.toLowerCase(cTail)) {
15 | return false;
16 | }
17 | head++;
18 | tail--;
19 | }
20 | }
21 | return true;
22 | }
23 | ```
24 |
--------------------------------------------------------------------------------
/2018.11.27-leetcode125/tongLuoWan.md:
--------------------------------------------------------------------------------
1 | >leetcode 125. Valid Palindrome
2 |
3 | ```
4 | class Solution {
5 |
6 | public boolean isPalindrome(String s) {
7 | if(s.length()==0)
8 | return true;
9 | s=s.toLowerCase();
10 | int i = 0, j = s.length()- 1;
11 | while (i2018.11.27号打卡
25 |
--------------------------------------------------------------------------------
/2018.11.27-leetcode125/家.md:
--------------------------------------------------------------------------------
1 | ```
2 | func isPalindrome(s string) bool {
3 | if len(s) <= 1 {return true}
4 | low, hi := 0, len(s) - 1
5 | for low < hi {
6 | for ; low < hi && !isValid(s[low]); low++ {}
7 | for ; low < hi && !isValid(s[hi]); hi--{}
8 | x, y := s[low], s[hi]
9 | if (x >= 'A' && x <= 'Z') {x = x - 'A' + 'a'}
10 | if (y >= 'A' && y <= 'Z') {y = y - 'A' + 'a'}
11 | if x != y {return false}
12 | low, hi = low+1, hi-1
13 | }
14 | return true
15 | }
16 |
17 | func isValid(b byte) bool {
18 | return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.11.27-leetcode125/我爱吃瓜子.md:
--------------------------------------------------------------------------------
1 | #leetcode 125
2 |
3 | ```
4 | class Solution {
5 | public boolean isPalindrome(String s) {
6 |
7 | String str = s.replaceAll("[^a-z^A-Z^0-9]", "");
8 | if(null == str ){
9 | return false;
10 | }else if( "".equals(str)){
11 | return true;
12 | }
13 | int i = 0;
14 | int j = str.length() - 1;
15 | String[] strings = str.split("");
16 |
17 | boolean flag = false;
18 | for (; i <= j; i++,j--) {
19 | if(! strings[i].equalsIgnoreCase(strings[j])){
20 | return false;
21 | }
22 | }
23 | return true;
24 | }
25 | }
26 | ```
27 |
--------------------------------------------------------------------------------
/2018.11.27-leetcode125/铁男神sama.java:
--------------------------------------------------------------------------------
1 | char[] charArray = s.toCharArray();
2 | StringBuilder sb = new StringBuilder();
3 | for(char c:charArray){
4 | if(Character.isDigit(c)||Character.isLetter(c)){
5 | sb.append(c);
6 | }
7 |
8 | }
9 |
10 | return sb.toString().toLowerCase().equals(sb.reverse().toString().toLowerCase());
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/Avalon.md:
--------------------------------------------------------------------------------
1 | public static String reverseWords(String input){
2 |
3 | String[] arr = input.trim().split("\\s+");//"\\s+"
4 | int len = arr.length;
5 | /*
6 | String[] result = new String[len];
7 | for (int i = 0;i=0; i--) {
8 | if(!str[i].equals("")){
9 | if (res.length()>0)
10 | res += " ";
11 | }
12 | res += str[i];
13 | }
14 | return res;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/GatesMa.md:
--------------------------------------------------------------------------------
1 | ```cpp
2 | class Solution {
3 | public:
4 | void reverseWords(string &s) {
5 | if(s.empty())
6 | return ;
7 | stringstream ss(s);
8 | vector words;
9 | string word;
10 | while(ss>>word)
11 | words.push_back(word+' ');
12 | if(!words.empty())
13 | {
14 | s.clear();
15 |
16 | for(int i=words.size()-1;i>=0;i--)
17 | {
18 | s+= words[i];
19 | }
20 | //s = s.substr(0,s.length()-1);
21 | s.pop_back();
22 | }
23 | else
24 | {
25 | s.clear();
26 | }
27 | }
28 | };
29 | ```
30 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/V1ncentzzZ:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public String reverseWords(String s) {
3 | StringBuilder result = new StringBuilder();
4 | if(s == null || s.length() == 0) return "";
5 | s = s.trim();
6 | String[] words = s.split(" ");
7 | for(int i=words.length-1; i>=0; i--){
8 | if("".equals(words[i])) continue;
9 | result.append(words[i]);
10 | if(i > 0) result.append(" ");
11 | }
12 | return result.toString();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/disappo1nted.md:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public String reverseWords(String s) {
3 | if(s==null || s.length()==0){
4 | return"";
5 | }
6 | String[] array=s.split(" ");
7 | String str="";
8 | for(int i = array.length-1;i>=0;--i){
9 | if(!array[i]equals("")){
10 | if(str.length()>0){
11 | str+=" ";
12 | }
13 | str+=array[i];
14 | }
15 | }
16 | return str;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/kiritocly.md:
--------------------------------------------------------------------------------
1 | private static String solution(String input) {
2 | if ("".equals(input) || input == null) {
3 | return "";
4 | }
5 | String[] splits = input.split(" ");
6 | //反转字符串中的单词,从尾到头遍历
7 | //单词之间以空格分离
8 | String result = " ";
9 | for (int i = splits.length - 1; i >= 0; i--) {
10 | if (!splits[i].equals("")) {
11 | //单词不为空
12 | result = result + splits[i];
13 | }
14 | }
15 | return result;
16 | }
17 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/不能吃太饱.md:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public String reverseWords(String s) {
3 | String[] ss=s.split(" ");
4 | StringBuilder answer=new StringBuilder();
5 | for(int i=ss.length-1;i>=0;i--) {
6 | ss[i]=ss[i].trim();
7 | if(!ss[i].equals("")&&ss[i]!=null) {
8 | System.out.println(ss[i]);
9 | answer.append(ss[i]+" ");
10 | }
11 | }
12 | return answer.toString().trim();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/大魔王爱穿孖烟筒.md:
--------------------------------------------------------------------------------
1 | ```
2 | public class Solution {
3 | public String reverseWords(String s) {
4 | if (s == null || s.length() == 0) {
5 | return "";
6 | }
7 | String[] array = s.split(" ");//按照空格划分字符串
8 | String str = "";
9 | for (int i = array.length - 1; i >= 0; i--) {
10 | if (!array[i].equals("")) {
11 | if (str.length() > 0) {
12 | str += " ";
13 | }
14 | str += array[i];//如果不是空字符串,就把截断的旧字符串添加到新字符串中。
15 | }
16 | }
17 | return str;
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/小熊君.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | public class LeetCode{
4 | public static void main(String args[]) {
5 | String s = "the sky is blue";
6 | System.out.println(leetcode(s));
7 | }
8 |
9 | public static String reverse(String s) {
10 | String[] str = s.split(" ");
11 | for(int i=0;i= 0; )
6 | {
7 | while (i >= 0 && s[i] == ' ') i--;
8 | if (i < 0) break;
9 | if (!rw.empty()) rw.push_back(' ');
10 | string t;
11 | while (i >= 0 && s[i] != ' ') t.push_back(s[i--]); //开始逆向输出
12 | reverse(t.begin(), t.end());
13 | rw.append(t);
14 | }
15 | s=rw;
16 | }
17 | };
18 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/晨曦雨露.md:
--------------------------------------------------------------------------------
1 | public static String reverseWords(String str) {
2 | str=str.trim();
3 | if(str.isEmpty()||str.length()==1||str.indexOf("\\s+")!=-1) {
4 | return str;
5 | }
6 | StringBuffer sb = new StringBuffer();
7 | String[] str1=str.split("\\s+");
8 | for (int i = 0; i < str1.length; i++) {
9 | if(i=0;i--){
9 | if(!array[i].equals("")){
10 | if(str.length()>0){
11 | str+=" ";
12 | }
13 | str += array[i];
14 | }
15 | }
16 | return str;
17 | }
18 |
19 | public static void main(String[] args) {
20 | String s = "hello world!";
21 | System.out.println(reverseWords(s));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/湛江甲鸟.md:
--------------------------------------------------------------------------------
1 | ```
2 | public static String reverseWords(String s) {
3 | int len = s.length();
4 | int j = len;
5 | String result = "";
6 | for (int i = len - 1; i >= 0; i--) {
7 | if (s.charAt(i) == ' '){
8 | j = i ;
9 | } else if (i == 0 || s.charAt(i - 1) == ' ') {
10 | if (result.length() != 0) {
11 | result += ' ';
12 | }
13 | result += s.substring(i, j);
14 | }
15 | }
16 | return result;
17 | }
18 |
--------------------------------------------------------------------------------
/2018.11.28-leetcode151/空白.md:
--------------------------------------------------------------------------------
1 |
2 | public String reverseWords(String s) {
3 | if(s == null || s.length() == 0){
4 | return s;
5 | }
6 | if (s.trim().length() == 0){ //对于只有空格的情况,则去除所有空格,返回即可
7 | return s.trim();
8 | }
9 | s = s.trim();//删除任何前导和尾随空格
10 | String ss[] = s.split(" "); //通过空格分隔
11 | String newS = "";
12 | for (int i=ss.length-1;i>=1;i--){
13 | if (ss[i].equals("")){ //句子中可能会有多余空格
14 | continue;
15 | }
16 | newS = newS+ss[i]+" ";
17 | }
18 | newS = newS+ss[0];
19 | System.out.println(newS);
20 | return newS;
21 | }
22 |
--------------------------------------------------------------------------------
/2018.11.29-leetcode443/Avalon.md:
--------------------------------------------------------------------------------
1 | public static int compress(char[] chars) {
2 | Map map = new LinkedHashMap();
3 | int len = chars.length;
4 | for (int i = 0; i entry : map.entrySet()) {
11 | num++;
12 | if (!entry.getValue().equals("1")){
13 | num += entry.getValue().toCharArray().length ;
14 | }
15 | }
16 | return num;
17 | }
18 |
--------------------------------------------------------------------------------
/2018.11.29-leetcode443/Sagittarius.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int compress(vector& chars) {
5 | int count=0;
6 | int index=0;
7 | for(int i=0;i 1) {
14 | for (char c : Integer.toString(cnt).toCharArray()) {
15 | chars[n++] = c;
16 | }
17 | }
18 | }
19 | return n;
20 | }
21 | }
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.11.29-leetcode443/zjukk.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int compress(vector& chars) {
5 | int N = chars.size();
6 | int idx = 0, cnt = 0;
7 |
8 | for(int i = 0; i < N; ++i) {
9 | cnt++;
10 | if (i == N-1 || chars[i] != chars[i+1]) {
11 | chars[idx++] = chars[i];
12 | if (cnt > 1) {
13 | for(auto c : to_string(cnt))
14 | chars[idx++] = c;
15 | }
16 | cnt = 0;
17 | }
18 | }
19 | return idx;
20 | }
21 | };
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.11.29-leetcode443/张小胖.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | int compress(vector& chars) {
4 | int n = chars.size(), char1 = 0;
5 | for (int i = 0, j = 0; i < n; i = j) {
6 | while (j < n && chars[j] == chars[i])
7 | ++j;
8 | chars[char1++] = chars[i];
9 | if (j - i == 1) continue;
10 | for (char c : to_string(j - i)) //个数
11 | chars[char1++] = c;
12 | }
13 | return char1;
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/2018.12.04-leetcode101/Saul.md:
--------------------------------------------------------------------------------
1 | ```java
2 | /**
3 | * Definition for a binary tree node.
4 | * public class TreeNode {
5 | * int val;
6 | * TreeNode left;
7 | * TreeNode right;
8 | * TreeNode(int x) { val = x; }
9 | * }
10 | */
11 | class Solution {
12 | public boolean isSymmetric(TreeNode root) {
13 | return isMirror(root, root);
14 | }
15 |
16 | public boolean isMirror(TreeNode t1, TreeNode t2) {
17 | if (t1 == null && t2 == null) return true;
18 | if (t1 == null || t2 == null) return false;
19 | return (t1.val == t2.val)
20 | && isMirror(t1.right, t2.left)
21 | && isMirror(t1.left, t2.right);
22 | }
23 | }
24 | ```
25 |
--------------------------------------------------------------------------------
/2018.12.04-leetcode101/啦啦啦.md:
--------------------------------------------------------------------------------
1 | ```java
2 | /**
3 | * Definition for a binary tree node.
4 | * public class TreeNode {
5 | * int val;
6 | * TreeNode left;
7 | * TreeNode right;
8 | * TreeNode(int x) { val = x; }
9 | * }
10 | */
11 | class Solution {
12 | public boolean isSymmetric(TreeNode root) {
13 | return cal(root,root);
14 | }
15 |
16 | boolean cal(TreeNode r1,TreeNode r2){
17 | if(r1==null&&r2==null)return true;
18 | if(r1==null||r2==null)return false;
19 | return r1.val==r2.val&&cal(r1.left,r2.right)&&cal(r1.right,r2.left);
20 | }
21 | }
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.12.05-leetcode102/Felix.md:
--------------------------------------------------------------------------------
1 | ```javascript
2 | public static void levelOrder(Node head){
3 | if(head == null){
4 | return;
5 | }
6 | Queue queue = new LinkedList<>();
7 | queue.offer(head);
8 | while(!queue.isEmpty()){
9 | head = queue.poll();
10 | System.out.print(head.value + " ");
11 | if(head.left != null){
12 | queue.offer(head.left);
13 | }
14 | if(head.right != null){
15 | queue.offer(head.right);
16 | }
17 | }
18 | }
19 |
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.05-leetcode102/GatesMa.md:
--------------------------------------------------------------------------------
1 | # C++
2 | ```cpp
3 | class Solution {
4 | public:
5 | vector> res;
6 | void check(TreeNode* root, int depth){
7 | if(root == NULL) return ;
8 | if(res.size() == depth)
9 | {
10 | res.push_back(vector());
11 | }
12 | res[depth].push_back(root->val);
13 | check(root->left, depth + 1);
14 | check(root->right, depth + 1);
15 | }
16 | vector> levelOrder(TreeNode* root) {
17 | check(root, 0);
18 | return res;
19 | }
20 | };
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.12.05-leetcode102/Sunny.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 |
4 | private List> result = new ArrayList<>();
5 |
6 | public List> levelOrder(TreeNode root) {
7 | levelOrder(root, 0);
8 | return result;
9 | }
10 |
11 | public void levelOrder(TreeNode node, int level) {
12 | if (node != null) {
13 | if (result.size() <= level) {
14 | result.add(new ArrayList());
15 | }
16 | result.get(level).add(node.val);
17 | levelOrder(node.left, level+1);
18 | levelOrder(node.right, level+1);
19 | }
20 | }
21 | }
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.12.05-leetcode102/二叉树的层次遍历.md:
--------------------------------------------------------------------------------
1 | 定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。
2 |
3 | 例如:
4 | 给定二叉树: [3,9,20,null,null,15,7],
5 |
6 | 3
7 | / \
8 | 9 20
9 | / \
10 | 15 7
11 | 返回其层次遍历结果:
12 |
13 | [
14 | [3],
15 | [9,20],
16 | [15,7]
17 | ]
18 |
--------------------------------------------------------------------------------
/2018.12.06-leetcode103/103. 二叉树的锯齿形层次遍历.md:
--------------------------------------------------------------------------------
1 | 给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。
2 |
3 | 例如:
4 | 给定二叉树: [3,9,20,null,null,15,7],
5 |
6 | 3
7 | / \
8 | 9 20
9 | / \
10 | 15 7
11 | 返回其层次遍历结果:
12 |
13 | [
14 | [3],
15 | [9,20],
16 | [15,7]
17 | ]
18 |
--------------------------------------------------------------------------------
/2018.12.06-leetcode103/zjukk.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | vector> zigzagLevelOrder(TreeNode* root) {
5 | vector> res;
6 | bfs(res,root,0,true);
7 | return res;
8 | }
9 | void bfs(vector>& res, TreeNode* root, int level, bool fromLeft) {
10 | if (!root) return;
11 | if (level == res.size()) res.push_back({});
12 | if (fromLeft) res[level].push_back(root->val);
13 | else res[level].insert(res[level].begin(),root->val);
14 | bfs(res,root->left,level+1,!fromLeft);
15 | bfs(res,root->right,level+1,!fromLeft);
16 | }
17 | };
18 | ```
19 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/-.md:
--------------------------------------------------------------------------------
1 | public class Solution_104 {
2 | public int maxDepth(TreeNode root) {
3 | int max = 0;
4 | if (null == root) {
5 | return 0;
6 | }
7 | max = 1;
8 | int left = maxDepth(root.left);
9 | int right = maxDepth(root.right);
10 | max = Math.max(left,right)+1;
11 |
12 | return max;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/104. 二叉树的最大深度:
--------------------------------------------------------------------------------
1 | 给定一个二叉树,找出其最大深度。
2 |
3 | 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
4 |
5 | 说明: 叶子节点是指没有子节点的节点。
6 |
7 | 示例:
8 | 给定二叉树 [3,9,20,null,null,15,7],
9 |
10 | 3
11 | / \
12 | 9 20
13 | / \
14 | 15 7
15 | 返回它的最大深度 3 。
16 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/FFFro.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int maxDepth(TreeNode root) {
3 | if (root == null)
4 | return 0;
5 | return depth(root);
6 | }
7 |
8 | private int depth(TreeNode root) {
9 | if (root == null)
10 | return 0;
11 | int left = depth(root.left);
12 | int right = depth(root.right);
13 | return left > right ? left+1 : right+1;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/GatesMa.md:
--------------------------------------------------------------------------------
1 | # c++
2 | ```cpp
3 | /**
4 | * Definition for a binary tree node.
5 | * struct TreeNode {
6 | * int val;
7 | * TreeNode *left;
8 | * TreeNode *right;
9 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
10 | * };
11 | */
12 | class Solution {
13 | public:
14 | int maxDepth(TreeNode* root) {
15 | return depth(root);
16 | }
17 | int depth(TreeNode* root) {
18 | if(root == NULL) return 0;
19 | int l = depth(root->left);
20 | int r = depth(root->right);
21 | return l > r ? l + 1 : r + 1;
22 | }
23 | };
24 | ```
25 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/Istoryforever.md:
--------------------------------------------------------------------------------
1 | leetcode of 104
2 | ```
3 | /**
4 | * Definition for a binary tree node.
5 | * struct TreeNode {
6 | * int val;
7 | * TreeNode *left;
8 | * TreeNode *right;
9 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
10 | * };
11 | */
12 | class Solution {
13 | public:
14 | int maxDepth(TreeNode* root) {
15 | if(root == nullptr){
16 | return 0;
17 | }
18 | int l = maxDepth(root->left);
19 | int r = maxDepth(root->right);
20 | int m = l > r ? l : r;
21 | return m+1;
22 | }
23 | };
24 | ```
25 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/MQQM.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | 题目:
3 | 给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数
4 | */
5 |
6 | /**
7 | * Definition for a binary tree node.
8 | * struct TreeNode {
9 | * int val;
10 | * TreeNode *left;
11 | * TreeNode *right;
12 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
13 | * };
14 | */
15 | class Solution {
16 | public:
17 | int maxDepth(TreeNode* root) {
18 | if(root==NULL)
19 | return 0;
20 | int leftDepth = maxDepth(root->left);
21 | int rightDepth = maxDepth(root->right);
22 | return (leftDepth > rightDepth) ? leftDepth+1 : rightDepth+1 ;
23 | }
24 | };
25 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | /**
3 | * Definition for a binary tree node.
4 | * struct TreeNode {
5 | * int val;
6 | * TreeNode *left;
7 | * TreeNode *right;
8 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
9 | * };
10 | */
11 | class Solution {
12 | public:
13 | int maxDepth(TreeNode* root) {
14 | if(root==NULL) return 0;
15 | return max(maxDepth(root->left),maxDepth(root->right))+1;
16 | }
17 | };
18 | ```
19 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/Saul.md:
--------------------------------------------------------------------------------
1 | ```java
2 | /**
3 | * Definition for a binary tree node.
4 | * public class TreeNode {
5 | * int val;
6 | * TreeNode left;
7 | * TreeNode right;
8 | * TreeNode(int x) { val = x; }
9 | * }
10 | */
11 | class Solution {
12 | public int maxDepth(TreeNode root) {
13 | if(root == null){
14 | return 0;
15 | }
16 | int leftLen = maxDepth(root.left);
17 | int rightLen = maxDepth(root.right);
18 | return Math.max(leftLen,rightLen)+1;
19 |
20 | }
21 | }
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/Sunny.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxDepth(TreeNode root) {
4 | if (root == null) return 0;
5 | return Math.max(maxDepth(root.left, 1), maxDepth(root.right, 1));
6 | }
7 |
8 | public int maxDepth(TreeNode node, int level) {
9 | if (node != null) {
10 | level = Math.max(maxDepth(node.left, level+1), maxDepth(node.right, level+1));
11 | }
12 | return level;
13 | }
14 | }
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | /**
3 | * Definition for a binary tree node.
4 | * public class TreeNode {
5 | * int val;
6 | * TreeNode left;
7 | * TreeNode right;
8 | * TreeNode(int x) { val = x; }
9 | * }
10 | */
11 | class Solution {
12 | public int maxDepth(TreeNode root) {
13 | if (root == null) {
14 | return 0;
15 | }
16 | return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```java
2 | /**
3 | * Definition for a binary tree node.
4 | * public class TreeNode {
5 | * int val;
6 | * TreeNode left;
7 | * TreeNode right;
8 | * TreeNode(int x) { val = x; }
9 | * }
10 | */
11 | class Solution {
12 | public int maxDepth(TreeNode root) {
13 | int left;
14 | int right;
15 | if (root == null){
16 | return 0;
17 | }
18 | else {
19 | left = maxDepth(root.left) + 1;
20 | right = maxDepth(root.right) + 1;
21 | }
22 | return left > right ? left : right;
23 | }
24 | }
25 | ```
26 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/disappo1nted.md:
--------------------------------------------------------------------------------
1 | /**
2 | * Definition for a binary tree node.
3 | * public class TreeNode {
4 | * int val;
5 | * TreeNode left;
6 | * TreeNode right;
7 | * TreeNode(int x) { val = x; }
8 | * }
9 | */
10 | class Solution {
11 | public int maxDepth(TreeNode root)
12 | {
13 | return Depth(root);
14 | }
15 | public int Depth(TreeNode root)
16 | {
17 | if(root==null)
18 | return 0;
19 | int left = maxDepth(root.left);
20 | int right = maxDepth(root.right);
21 | return left>right?left+1:right+1;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/justwe.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int maxDepth(TreeNode root) {
3 | if(root==null)
4 | return 0;
5 | else{
6 | int lTree = maxDepth(root.left);
7 | int rTree = maxDepth(root.right);
8 | return java.lang.Math.max(lTree, rTree)+1;
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/syuan.md:
--------------------------------------------------------------------------------
1 | ```
2 | /**
3 | * Definition for a binary tree node.
4 | * public class TreeNode {
5 | * int val;
6 | * TreeNode left;
7 | * TreeNode right;
8 | * TreeNode(int x) { val = x; }
9 | * }
10 | */
11 | class Solution {
12 | public int maxDepth(TreeNode root) {
13 | if (root == null) {
14 | return 0;
15 | }
16 |
17 | return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/zjukk.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int maxDepth(TreeNode* root) {
5 | if (!root) return 0;
6 | int left = maxDepth(root->left);
7 | int right = maxDepth(root->right);
8 | return max(left,right)+1;
9 | }
10 | };
11 | ```
12 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/利爪德鲁伊.md:
--------------------------------------------------------------------------------
1 | /**
2 | * Definition for a binary tree node.
3 | * public class TreeNode {
4 | * int val;
5 | * TreeNode left;
6 | * TreeNode right;
7 | * TreeNode(int x) { val = x; }
8 | * }
9 | */
10 | class Solution {
11 | public int maxDepth(TreeNode root) {
12 | if (root == null) return 0;
13 | return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/张小胖.md:
--------------------------------------------------------------------------------
1 | /**
2 | Definition for a binary tree node.
3 | struct TreeNode{
4 | int val;
5 | TreeNode *left;
6 | TreeNode *right;
7 | TreeNode(int x):val(x),left(NULL),right(NULL) {}
8 | };
9 | */
10 | class Solution{
11 | public:
12 | int maxDepth(TreeNode* root){
13 | if(root==nullptr) return 0;
14 | int leftDepth=maxDepth(root->left);
15 | int rightDepth=maxDepth(root->right);
16 | if(leftDepth>rightDepth) return leftDepth+1;
17 | else return rightDepth+1;
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/棕榈树.md:
--------------------------------------------------------------------------------
1 | ```
2 | /**
3 | * Definition for a binary tree node.
4 | * public class TreeNode {
5 | * int val;
6 | * TreeNode left;
7 | * TreeNode right;
8 | * TreeNode(int x) { val = x; }
9 | * }
10 | */
11 | class Solution {
12 | public int maxDepth(TreeNode root) {
13 | if(root==null){
14 | return 0;
15 | }
16 | int left = maxDepth(root.left);
17 | int right = maxDepth(root.right);
18 | return Math.max(left,right)+1;
19 | }
20 | }
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/莎莎.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution:
3 | def maxDepth(self, root):
4 | """
5 | :type root: TreeNode
6 | :rtype: int
7 | """
8 | q = [root]
9 | j = 0
10 | if not root:
11 | return 0
12 | while q:
13 | for i in range(len(q)):
14 | temp = q.pop(0)
15 | if temp.left:
16 | q.append(temp.left)
17 | if temp.right:
18 | q.append(temp.right)
19 | j += 1
20 | return j
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.12.07-leetcode104/阳.md:
--------------------------------------------------------------------------------
1 | /**
2 | * Definition for a binary tree node.
3 | * public class TreeNode {
4 | * int val;
5 | * TreeNode left;
6 | * TreeNode right;
7 | * TreeNode(int x) { val = x; }
8 | * }
9 | */
10 | class Solution {
11 | public int maxDepth(TreeNode root) {
12 | if(root == null) {
13 | return 0;
14 | }
15 | return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/2018.12.08-leetcode105/105. 从前序与中序遍历序列构造二叉树.md:
--------------------------------------------------------------------------------
1 |
2 | 根据一棵树的前序遍历与中序遍历构造二叉树。
3 |
4 | 注意:
5 | 你可以假设树中没有重复的元素。
6 |
7 | 例如,给出
8 |
9 | 前序遍历 preorder = [3,9,20,15,7]
10 | 中序遍历 inorder = [9,3,15,20,7]
11 | 返回如下的二叉树:
12 |
13 | 3
14 | / \
15 | 9 20
16 | / \
17 | 15 7
18 |
--------------------------------------------------------------------------------
/2018.12.08-leetcode105/莎莎.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution:
3 | def buildTree(self, preorder, inorder):
4 | """
5 | :type preorder: List[int]
6 | :type inorder: List[int]
7 | :rtype: TreeNode
8 | """
9 | if not preorder:
10 | return None
11 | root = TreeNode(preorder[0])
12 | n = inorder.index(root.val)
13 | root.left = self.buildTree(preorder[1:n+1],inorder[:n])
14 | root.right = self.buildTree(preorder[n+1:],inorder[n+1:])
15 | return root
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.09-leetcode106/106. 从中序与后序遍历序列构造二叉树.md:
--------------------------------------------------------------------------------
1 |
2 | 根据一棵树的中序遍历与后序遍历构造二叉树。
3 |
4 | 注意:
5 | 你可以假设树中没有重复的元素。
6 |
7 | 例如,给出
8 |
9 | 中序遍历 inorder = [9,3,15,20,7]
10 | 后序遍历 postorder = [9,15,7,20,3]
11 | 返回如下的二叉树:
12 |
13 | 3
14 | / \
15 | 9 20
16 | / \
17 | 15 7
18 |
--------------------------------------------------------------------------------
/2018.12.09-leetcode106/莎莎.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution:
3 | def buildTree(self, inorder, postorder):
4 | """
5 | :type inorder: List[int]
6 | :type postorder: List[int]
7 | :rtype: TreeNode
8 | """
9 | if not postorder:
10 | return None
11 | root = TreeNode(postorder[-1])
12 | n = inorder.index(root.val)
13 | root.left = self.buildTree(inorder[:n],postorder[0:n])
14 | root.right = self.buildTree(inorder[n+1:],postorder[n:-1])
15 | return root
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/GatesMa.md:
--------------------------------------------------------------------------------
1 | # c++
2 | ```cpp
3 | class Solution {
4 | public:
5 | int firstUniqChar(string s) {
6 | int chnum[26];
7 | memset(chnum, 0, sizeof(chnum));
8 | int len = s.length();
9 | for(int i=0;i m;
9 | //string ss(s);
10 | for(auto c : s){
11 | if(m.count(c) == 0) m[c]=1;
12 | else m[c]++;
13 | }
14 | for(auto i = s.begin();i!=s.end();i++){
15 | if(m[*i] == 1) return i-s.begin();
16 | }
17 | return -1;
18 |
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int firstUniqChar(string s) {
5 | int len = s.length();
6 | if(len==1) return 0;
7 | map mp;
8 | int ans = -1;
9 | for(int i = len-1; i >= 0; i--){
10 | mp[s[i]]++;
11 | }
12 | for(int i = len-1; i>= 0; i--){
13 | if(mp[s[i]]==1) ans = i;
14 | }
15 | return ans;
16 |
17 | }
18 | };
19 | ```
20 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/Sagittarius.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int firstUniqChar(string s) {
5 | int a[26]={0};
6 | for(int i=0;i countMap;
11 | s += '\0';
12 | char *sHead = (char *)s.data();
13 | char *head = sHead;
14 | while (*sHead != '\0')
15 | {
16 | countMap[*sHead]++;
17 | ++sHead;
18 | }
19 | for (int i = 0; i < s.size(); i++) {
20 | if (countMap[s[i]] == 1){
21 | return i;
22 | }
23 | }
24 | return -1;
25 | }
26 | };
27 | ```
28 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/justwe.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int firstUniqChar(String s) {
3 | if(null == s || 0 == s.length() )
4 | return -1;
5 | int[] hash = new int[26];//记录26个字母的字符数组
6 | char[] array = s.toCharArray();//将字符串转为字符数组
7 | //通过遍历字符数组,查看字符串中每个字母出现的次数
8 | for(int i = 0; i < array.length; i++){
9 | int num = array[i] - 'a';
10 |
11 | hash[num]++;
12 | }
13 | for(int i = 0; i < array.length; i++){//从字符串出发
14 | //获得26个字母的下标
15 | int num = array[i] - 'a';
16 | if(hash[num] == 1){
17 | return i;
18 | }
19 | }
20 | return -1;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 387
2 | class Solution {
3 | public int firstUniqChar(String s) {
4 | if (s.length() == 0 || s == null) {
5 | return -1;
6 | }
7 | int[] arr = new int[26];
8 | for (int i = 0; i < s.length(); i++) {
9 | arr[s.charAt(i) - 'a']++;
10 | }
11 | for (int i = 0; i < s.length(); i++) {
12 | if (arr[s.charAt(i)-'a']==1) {
13 | return i;
14 | }
15 | }
16 | return -1;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/云深不叹.md:
--------------------------------------------------------------------------------
1 | ```
2 | public int firstUniqChar(String s) {
3 | if(s==null || s.trim().equals("")){
4 | return -1;
5 | }
6 | char[] chars = s.toCharArray();
7 | int res = -1;
8 | for(char c : chars){
9 | int index = s.indexOf(c);
10 | if(index == s.lastIndexOf(c)){
11 | return index;
12 | }
13 | }
14 | return res;
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/云胡不喜.md:
--------------------------------------------------------------------------------
1 | public class Solution {
2 | public int lengthOfLastWord(String s) {
3 | int result = 0,i = s.length()-1;
4 | while( i>=0 && s.charAt(i) == ' ' ){
5 | i--;
6 | }
7 | while( i>=0 && s.charAt(i) != ' '){
8 | result++;
9 | i--;
10 | }
11 | return result;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/大魔王爱穿孖烟筒.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int firstUniqChar(String s) {
4 |
5 | char[] arr = s.toCharArray();
6 | int[] count = new int[26];//创建字母表数组
7 | for(int i =0;i number(26);
6 | int i;
7 | for(i=0;i index) ? index : res;
9 | }
10 | }
11 | return res;
12 | }
13 |
14 | ```
15 |
--------------------------------------------------------------------------------
/2018.12.1-leetcode387/神秘的火柴人.md:
--------------------------------------------------------------------------------
1 | ...
2 | class Solution {
3 | public:
4 | int firstUniqChar(string s) {
5 | if(s.length() == 1)
6 | return 0;
7 | if(s.length() == 0)
8 | return -1;
9 |
10 | map m;
11 | int i = 0;
12 | for(i=0; i map=new HashMap<>();
8 | for(int i=0;i end)
10 | return null;
11 | if (start == end)
12 | return new TreeNode(nums[start]);
13 | int mid = start + (end - start) / 2;
14 | TreeNode root = new TreeNode(nums[mid]);
15 | root.left = build(nums,start,mid-1);
16 | root.right = build(nums,mid+1,end);
17 | return root;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/2018.12.11-leetcode108/Sunny.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public TreeNode sortedArrayToBST(int[] nums) {
4 | if (nums == null || nums.length == 0)
5 | return null;
6 | int i = nums.length / 2;
7 | TreeNode node = new TreeNode(nums[i]);
8 | if (i > 0) {
9 | node.left = sortedArrayToBST(Arrays.copyOfRange(nums, 0, i));
10 | if (i+1 < nums.length) {
11 | node.right = sortedArrayToBST(Arrays.copyOfRange(nums, i+1, nums.length));
12 | }
13 | }
14 | return node;
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.12.11-leetcode108/莎莎.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution:
3 | def sortedArrayToBST(self, nums):
4 | """
5 | :type nums: List[int]
6 | :rtype: TreeNode
7 | """
8 | if not nums:
9 | return None
10 |
11 | n = len(nums)//2
12 |
13 | root = TreeNode(nums[n])
14 | root.left = self.sortedArrayToBST(nums[:n])
15 | root.right = self.sortedArrayToBST(nums[n+1:])
16 | return root
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.12.12-leetcode109/109. 有序链表转换二叉搜索树:
--------------------------------------------------------------------------------
1 | 给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树。
2 |
3 | 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。
4 |
5 | 示例:
6 |
7 | 给定的有序链表: [-10, -3, 0, 5, 9],
8 |
9 | 一个可能的答案是:[0, -3, 9, -10, null, 5], 它可以表示下面这个高度平衡二叉搜索树:
10 |
11 | 0
12 | / \
13 | -3 9
14 | / /
15 | -10 5
16 |
--------------------------------------------------------------------------------
/2018.12.13-leetcode215/215. 数组中的第K个最大元素:
--------------------------------------------------------------------------------
1 | 在未排序的数组中找到第 k 个最大的元素。请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。
2 |
3 | 示例 1:
4 |
5 | 输入: [3,2,1,5,6,4] 和 k = 2
6 | 输出: 5
7 | 示例 2:
8 |
9 | 输入: [3,2,3,1,2,4,5,5,6] 和 k = 4
10 | 输出: 4
11 | 说明:
12 |
13 | 你可以假设 k 总是有效的,且 1 ≤ k ≤ 数组的长度。
14 |
--------------------------------------------------------------------------------
/2018.12.13-leetcode215/GatesMa.md:
--------------------------------------------------------------------------------
1 | # c++
2 | ```cpp
3 | class Solution {
4 | public:
5 | static bool cmp(int a, int b) {
6 | return a > b;
7 | }
8 | int findKthLargest(vector& nums, int k) {
9 | sort(nums.begin(), nums.end(), cmp);
10 | return nums[k-1];
11 | }
12 | };
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.13-leetcode215/MQQM.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | 题目:
3 | 在未排序的数组中找到第k大的元素。
4 | */
5 | class Solution {
6 | public:
7 | int findKthLargest(vector& nums, int k) {
8 | sort(nums.begin(), nums.end());
9 | return nums[nums.size()-k];
10 | }
11 | };
12 |
--------------------------------------------------------------------------------
/2018.12.13-leetcode215/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int findKthLargest(vector& nums, int k) {
5 | sort(nums.begin(),nums.end(),greater());
6 | return nums[k-1];
7 | }
8 | };
9 | ```
10 |
11 | ```
12 | class Solution {
13 | public:
14 | int findKthLargest(vector& nums, int k) {
15 | int size = nums.size();
16 | nth_element(nums.begin(),nums.begin()+size-k,nums.end());
17 | return nums[size-k];
18 | }
19 | };
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.13-leetcode215/Sagittarius.md:
--------------------------------------------------------------------------------
1 | ```
2 | static auto io_sync_off = [] () {
3 | std::cin.tie(nullptr);
4 | std::ios::sync_with_stdio(false);
5 | std::cout.tie(nullptr);
6 | return nullptr;
7 | }();
8 | class Solution {
9 | public:
10 | int findKthLargest(vector& nums, int k) {
11 | nth_element(nums.begin(),nums.end()-k,nums.end());
12 | return nums[nums.size()-k];
13 | }
14 | };
15 |
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.13-leetcode215/Sunny.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int findKthLargest(int[] nums, int k) {
4 | if (nums == null || nums.length == 0) {
5 | return -1;
6 | }
7 | List sorted = new ArrayList<>();
8 | for (int i=0; i sorted = Arrays.stream(nums).boxed().collect(Collectors.toList());
12 | sorted.sort((a,b) -> b-a);
13 | return sorted.get(k-1);
14 | }
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.13-leetcode215/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```python
2 | class Solution(object):
3 | def findKthLargest(self, nums, k):
4 | """
5 | :type nums: List[int]
6 | :type k: int
7 | :rtype: int
8 | """
9 | nums.sort(reverse=True)
10 | return nums[k-1]
11 | ```
12 | ```java
13 | class Solution {
14 | public int findKthLargest(int[] nums, int k) {
15 | // 经过调优的快速排序法
16 | Arrays.sort(nums);
17 | return nums[nums.length-k];
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.13-leetcode215/Typing.txt:
--------------------------------------------------------------------------------
1 | public class Main215 {
2 | public static void main(String[] args){
3 | Main215 main = new Main215();
4 | main.test();
5 | }
6 |
7 | private void test() {
8 | System.out.println(findKthLargest(new int[]{3,2,3,1,2,4,5,5,6},4));
9 | }
10 |
11 | public int findKthLargest(int[] nums, int k) {
12 | Arrays.sort(nums);
13 | for(int i = nums.length-1;i>=0;i--){
14 | if (--k==0)
15 | return nums[i];
16 | }
17 | return nums[0];
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/2018.12.14-leetcode347/347. 前K个高频元素:
--------------------------------------------------------------------------------
1 | 给定一个非空的整数数组,返回其中出现频率前 k 高的元素。
2 |
3 | 示例 1:
4 |
5 | 输入: nums = [1,1,1,2,2,3], k = 2
6 | 输出: [1,2]
7 | 示例 2:
8 |
9 | 输入: nums = [1], k = 1
10 | 输出: [1]
11 | 说明:
12 |
13 | 你可以假设给定的 k 总是合理的,且 1 ≤ k ≤ 数组中不相同的元素的个数。
14 | 你的算法的时间复杂度必须优于 O(n log n) , n 是数组的大小。
15 |
--------------------------------------------------------------------------------
/2018.12.14-leetcode347/Sunny.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public List topKFrequent(int[] nums, int k) {
4 | Map map = new HashMap<>();
5 | for (int n: nums) {
6 | map.put(n, map.getOrDefault(n, 0) + 1);
7 | }
8 | List result = new ArrayList<>();
9 | PriorityQueue heap = new PriorityQueue<>((a, b) -> map.get(b) - map.get(a));
10 | for (int num : map.keySet()) {
11 | heap.add(num);
12 | }
13 | for (int j=0; j topKFrequent(vector& nums, int k) {
7 | unordered_map m;
8 | priority_queue> q;
9 | vector res;
10 | for (auto a : nums) ++m[a];
11 | for (auto it : m) q.push(make_pair(it.second, it.first));
12 | for (int i = 0; i < k; ++i) {
13 | res.push_back(q.top().second); q.pop();
14 | }
15 | return res;
16 | }
17 | };
18 | ```
19 |
--------------------------------------------------------------------------------
/2018.12.15-leetcode451/451. 根据字符出现频率排序:
--------------------------------------------------------------------------------
1 | 给定一个字符串,请将字符串里的字符按照出现的频率降序排列。
2 |
3 | 示例 1:
4 |
5 | 输入:
6 | "tree"
7 |
8 | 输出:
9 | "eert"
10 |
11 | 解释:
12 | 'e'出现两次,'r'和't'都只出现一次。
13 | 因此'e'必须出现在'r'和't'之前。此外,"eetr"也是一个有效的答案。
14 | 示例 2:
15 |
16 | 输入:
17 | "cccaaa"
18 |
19 | 输出:
20 | "cccaaa"
21 |
22 | 解释:
23 | 'c'和'a'都出现三次。此外,"aaaccc"也是有效的答案。
24 | 注意"cacaca"是不正确的,因为相同的字母必须放在一起。
25 | 示例 3:
26 |
27 | 输入:
28 | "Aabb"
29 |
30 | 输出:
31 | "bbAa"
32 |
33 | 解释:
34 | 此外,"bbaA"也是一个有效的答案,但"Aabb"是不正确的。
35 | 注意'A'和'a'被认为是两种不同的字符。
36 |
--------------------------------------------------------------------------------
/2018.12.15-leetcode451/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | string frequencySort(string s) {
5 | int len = s.size();
6 | unordered_map hash;
7 | vector vec(len+1, "");
8 | for(auto ch: s) hash[ch]++;
9 | for(auto val: hash) vec[val.second].append(val.second, val.first);
10 | string ans;
11 | for(int i = len; i > 0; i--)
12 | ans += vec[i];
13 | return ans;
14 | }
15 | };
16 |
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.12.15-leetcode451/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```python
2 | from collections import Counter
3 | class Solution(object):
4 | def topKFrequent(self, nums, k):
5 | """
6 | :type nums: List[int]
7 | :type k: int
8 | :rtype: List[int]
9 | """
10 | c = Counter(nums)
11 | return [item[0] for item in c.most_common(k)]
12 | ```
13 |
--------------------------------------------------------------------------------
/2018.12.15-leetcode451/神秘的火柴人.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | string frequencySort(string s) {
5 | unordered_map m;
6 | for(auto ch:s) m[ch]++;
7 |
8 | priority_queue> p;
9 | for(auto var:m)
10 | p.push(make_pair(var.second, var.first));
11 |
12 | string ret;
13 | int len = p.size();
14 | for(int i=0; i& nums) {
6 | sort(nums.begin(),nums.end());
7 | }
8 | };
9 | ```
10 |
--------------------------------------------------------------------------------
/2018.12.16-leetcode75/Sagittarius.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | void sortColors(vector& nums) {
5 | int start=-1;
6 | int end=nums.size();
7 | int index=0;
8 | while(index1)
13 | swap(nums[--end],nums[index]);
14 | else
15 | index++;
16 | }
17 |
18 | }
19 | };
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.16-leetcode75/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public void sortColors(int[] nums) {
4 | int l = 0;
5 | int r = nums.length;
6 | int i = 0;
7 | while (i < r) {
8 | if (nums[i] < 1) swap(nums, i++, l++);
9 | else if (nums[i] > 1) swap(nums, i, --r);
10 | else ++i;
11 | }
12 | }
13 |
14 | private static void swap(int[] nums, int i, int j) {
15 | int tmp = nums[i];
16 | nums[i] = nums[j];
17 | nums[j] = tmp;
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.16-leetcode75/XXXX.md:
--------------------------------------------------------------------------------
1 | ## 看了公众号关于GitHub文章过来的,第一次尝试
2 | ## 今天就不写代码了,第一次还不懂规矩,先学会使用GitHub吧
3 | print("Hello world!")
4 |
--------------------------------------------------------------------------------
/2018.12.16-leetcode75/神秘的火柴人.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | void sortColors(vector& nums) {
5 | int i=0;
6 | int j=nums.size()-1;
7 |
8 | int index = 0;
9 | while(index <= j)
10 | {
11 | if(nums[index]==0 && index!=i)
12 | {
13 | swap(nums[index], nums[i]);
14 | i++;
15 |
16 | }
17 | else if(nums[index]==2)
18 | {
19 | swap(nums[index], nums[j]);
20 | j--;
21 | }
22 | else
23 | index++;
24 | }
25 |
26 | }
27 | };
28 | ```
29 |
--------------------------------------------------------------------------------
/2018.12.17-leetcode445/嗯.md:
--------------------------------------------------------------------------------
1 | import java.util.Arrays;
2 | class Solution {
3 | public int findContentChildren(int[] g, int[] s) {
4 | int res = 0; //用来存放的是满足的个数
5 | Arrays.sort(g);//升序排序
6 | Arrays.sort(s);//升序排序
7 | //遍历
8 | for (int i = 0, j = 0; i < s.length && j < g.length; i++) {
9 | if (s[i] >= g[j]) {
10 | res++;
11 | j++;
12 | }
13 | }
14 | return res;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/2018.12.17-leetcode455/455. 分发饼干.md:
--------------------------------------------------------------------------------
1 | 假设你是一位很棒的家长,想要给你的孩子们一些小饼干。
2 | 但是,每个孩子最多只能给一块饼干。
3 | 对每个孩子 i ,都有一个胃口值 gi ,这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j ,都有一个尺寸 sj 。
4 | 如果 sj >= gi ,我们可以将这个饼干 j 分配给孩子 i ,这个孩子会得到满足。
5 | 你的目标是尽可能满足越多数量的孩子,并输出这个最大数值。
6 |
7 | 注意:
8 |
9 | 你可以假设胃口值为正。
10 | 一个小朋友最多只能拥有一块饼干。
11 |
12 | 示例 1:
13 |
14 | 输入: [1,2,3], [1,1]
15 |
16 | 输出: 1
17 |
18 | 解释:
19 | 你有三个孩子和两块小饼干,3个孩子的胃口值分别是:1,2,3。
20 | 虽然你有两块小饼干,由于他们的尺寸都是1,你只能让胃口值是1的孩子满足。
21 | 所以你应该输出1。
22 | 示例 2:
23 |
24 | 输入: [1,2], [1,2,3]
25 |
26 | 输出: 2
27 |
28 | 解释:
29 | 你有两个孩子和三块小饼干,2个孩子的胃口值分别是1,2。
30 | 你拥有的饼干数量和尺寸都足以让所有孩子满足。
31 | 所以你应该输出2.
32 |
--------------------------------------------------------------------------------
/2018.12.17-leetcode455/Avalon.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int findContentChildren(int[] g, int[] s) {
3 | /**
4 | * 第一步:排序
5 | */
6 | Arrays.sort(g);
7 | Arrays.sort(s);//按照从小到大进行排序
8 | int gIndex =0,count = 0;
9 | for (int i=0;i=g[gIndex]){
12 | count++;
13 | gIndex++;
14 | break;
15 | }
16 | }
17 | }
18 | return count;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/2018.12.17-leetcode455/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int findContentChildren(int[] g, int[] s) {
4 | Arrays.sort(g);
5 | Arrays.sort(s);
6 | int i = 0;
7 | int j = 0;
8 | while (i < g.length && j < s.length) {
9 | if (s[j] >= g[i]) {
10 | ++i;
11 | }
12 | ++j;
13 | }
14 | return i;
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.12.17-leetcode455/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 455
2 | class Solution {
3 | public int findContentChildren(int[] g, int[] s) {//思路:先把小的饼干分发出去
4 | if (g == null || g.length == 0 || s == null || s.length == 0) {
5 | return 0;
6 | }
7 | Arrays.sort(g);
8 | Arrays.sort(s);
9 | int count=0;
10 | for (int i = 0, j = 0; i < g.length && j < s.length; ) {
11 | if (s[j] >= g[i]) {
12 | count++;
13 | i++;
14 | j++;
15 | } else {
16 | j++;
17 | }
18 | }
19 | return count;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/2018.12.17-leetcode455/刘润泽(capture).md:
--------------------------------------------------------------------------------
1 | ```java
2 | public static int findContentChildren(int[] g, int[] s) {
3 | int count=0;
4 | int index=0;
5 | Arrays.sort(g);
6 | Arrays.sort(s);
7 | for (int i=0;i& g, vector& s) {
5 | sort(g.begin(), g.end());
6 | sort(s.begin(), s.end());
7 |
8 | int i = 0;
9 | int j = 0;
10 | int count = 0;
11 | while(i < g.size() && j < s.size())
12 | {
13 | if(g[i] <= s[j])
14 | {
15 | i++;
16 | j++;
17 | count++;
18 | }
19 | else
20 | j++;
21 | }
22 |
23 | return count;
24 | }
25 | };
26 | ```
27 |
--------------------------------------------------------------------------------
/2018.12.18-leetcode435/435. 无重叠区间.md:
--------------------------------------------------------------------------------
1 | 给定一个区间的集合,找到需要移除区间的最小数量,使剩余区间互不重叠。
2 |
3 | 注意:
4 |
5 | 可以认为区间的终点总是大于它的起点。
6 | 区间 [1,2] 和 [2,3] 的边界相互“接触”,但没有相互重叠。
7 | 示例 1:
8 |
9 | 输入: [ [1,2], [2,3], [3,4], [1,3] ]
10 |
11 | 输出: 1
12 |
13 | 解释: 移除 [1,3] 后,剩下的区间没有重叠。
14 | 示例 2:
15 |
16 | 输入: [ [1,2], [1,2], [1,2] ]
17 |
18 | 输出: 2
19 |
20 | 解释: 你需要移除两个 [1,2] 来使剩下的区间没有重叠。
21 | 示例 3:
22 |
23 | 输入: [ [1,2], [2,3] ]
24 |
25 | 输出: 0
26 |
27 | 解释: 你不需要移除任何区间,因为它们已经是无重叠的了。
28 |
--------------------------------------------------------------------------------
/2018.12.19-leetcode452/452. 用最少数量的箭引爆气球.md:
--------------------------------------------------------------------------------
1 | 在二维空间中有许多球形的气球。
2 | 对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标。
3 | 由于它是水平的,所以y坐标并不重要,因此只要知道开始和结束的x坐标就足够了。
4 | 开始坐标总是小于结束坐标。平面内最多存在104个气球。
5 |
6 | 一支弓箭可以沿着x轴从不同点完全垂直地射出。
7 | 在坐标x处射出一支箭,若有一个气球的直径的开始和结束坐标为 xstart,xend, 且满足 xstart ≤ x ≤ xend,则该气球会被引爆。
8 | 可以射出的弓箭的数量没有限制。
9 | 弓箭一旦被射出之后,可以无限地前进。
10 | 我们想找到使得所有气球全部被引爆,所需的弓箭的最小数量。
11 |
12 | Example:
13 |
14 | 输入:
15 | [[10,16], [2,8], [1,6], [7,12]]
16 |
17 | 输出:
18 | 2
19 |
20 | 解释:
21 | 对于该样例,我们可以在x = 6(射爆[2,8],[1,6]两个气球)和 x = 11(射爆另外两个气球)。
22 |
--------------------------------------------------------------------------------
/2018.12.19-leetcode452/Avalon.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int findMinArrowShots(int[][] points) {
3 | if (points == null || points.length == 0) return 0;
4 | //对二位数组进行排序
5 | Arrays.sort(points, (x, y) -> x[1] - y[1]);
6 |
7 | //开始落实比较方案
8 | //1-无重叠区域
9 | int count = 0, j = 1;
10 | for (int i = 0; j < points.length; j++) {
11 | if (points[i][1] >= points[j][0]) {//被比较方的结束大于比较方的开始--重叠了-》
12 |
13 | } else {
14 | count++;//因为这个是后结算的,所以需要在最后return 的时候自加
15 | i = j;
16 | }
17 | }
18 |
19 | return ++count;//当最后一个出现的时候是木有进行判断
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/2018.12.19-leetcode452/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int findMinArrowShots(int[][] points) {
4 | if (points == null || points.length == 0) {
5 | return 0;
6 | }
7 | Arrays.sort(points, Comparator.comparingInt(o -> o[1]));
8 | int res = 1;
9 | int pre = points[0][1];
10 | for (int i = 1; i < points.length; ++i) {
11 | if (points[i][0] > pre) {
12 | ++res;
13 | pre = points[i][1];
14 | }
15 | }
16 | return res;
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/557. 反转字符串中的单词 III:
--------------------------------------------------------------------------------
1 | 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。
2 |
3 | 示例 1:
4 |
5 | 输入: "Let's take LeetCode contest"
6 | 输出: "s'teL ekat edoCteeL tsetnoc"
7 | 注意:在字符串中,每个单词由单个空格分隔,并且字符串中不会有任何额外的空格。
8 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/Avalon.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public String reverseWords(String s) {
3 | String[] sArr = s.split(" ");
4 | StringBuilder sb = new StringBuilder();
5 | int len = sArr.length;
6 | for (int i=0;i strs;
10 | while(ss){
11 | ss >> temstr;
12 | reverse(temstr.begin(),temstr.end());
13 | strs.push_back(temstr);
14 | }
15 | strs.pop_back();
16 | int len = strs.size();
17 | str += strs[0];
18 | for(int i =1;i < len;i++){
19 | str += " " + strs[i];
20 | }
21 | return str;
22 | }
23 | };
24 | ```
25 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/HCL6666HCL.md:
--------------------------------------------------------------------------------
1 | String.prototype.reverse = function() {
2 | return this.split('').reverse().join('');
3 | }
4 |
5 | var reverseWords = function(s) {
6 | return s.split(' ').map(str => str.reverse()).join(' ');
7 | };
8 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/Istoryforever.md:
--------------------------------------------------------------------------------
1 | leetcode of 557
2 | class Solution {
3 | public:
4 | string reverseWords(string s) {
5 | string ans;
6 | string t;
7 | stringstream ss(s);
8 | int start = 1;
9 | while(getline(ss,t,' ')){
10 | reverse(t.begin(),t.end());
11 | if(start){
12 | ans = t;
13 | start = 0;
14 | }else{
15 | ans += " "+t;
16 | }
17 | }
18 | return ans;
19 |
20 | }
21 | };
22 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | string reverseWords(string s) {
5 | s+=" ";
6 | int len = s.length();
7 | int left = 0, right = 0;
8 | for(int i = 0; i < len; i++){
9 | while(s[i]!=' ') right++,i++;
10 | reverse(s.begin()+left,s.begin()+right);
11 | right++;
12 | left=right;
13 | }
14 | s.pop_back();
15 | cout< a;
7 | int i=0;
8 | while(i>word){
11 | reverse(word.begin(), word.end());
12 | result += word + " ";
13 | }
14 | if(!result.empty())
15 | {
16 | result.erase(result.find_last_not_of(" ")+1);
17 | }
18 | return result;
19 | }
20 | };
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/wangli_eic:
--------------------------------------------------------------------------------
1 | class Solution:
2 | def reverseWords(self, s):
3 | """
4 | :type s: str
5 | :rtype: str
6 | """
7 | words = s.split()
8 | s_new = ''
9 | for i in range(len(words)):
10 | s_new += ' '+ words[i][::-1]
11 | return s_new.strip()
12 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/。。。.md:
--------------------------------------------------------------------------------
1 | public String reverseWords(String s) {
2 | char[] chars = s.toCharArray();
3 | int len = 0;
4 | for (int i = 0; i <= chars.length; i++){
5 | if (i == chars.length || chars[i] == ' '){
6 | for (int j = i-len-1; j >= 1; j-=2){
7 | char temp = chars[len];
8 | chars[len] = chars[len+j];
9 | chars[len+j] = temp;
10 | len++;
11 | }
12 | len = i+1;
13 | }
14 | }
15 | return new String(chars);
16 | }
17 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/云深不叹.md:
--------------------------------------------------------------------------------
1 | ```
2 | public String reverseWords(String s) {
3 | String[] arr = s.split(" ");
4 | StringBuilder sb = new StringBuilder();
5 | for (String str : arr){
6 | char[] chars = str.toCharArray();
7 | for (int i = chars.length -1; i>=0;i--){
8 | sb.append(chars[i]);
9 | }
10 | sb.append(" ");
11 | }
12 | return sb.substring(0,sb.length()-1);
13 |
14 | }
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/我爱吃瓜子.md:
--------------------------------------------------------------------------------
1 | #leetcode557
2 | ```
3 | class Solution {
4 | public String reverseWords(String s) {
5 | String[] words=s.split(" ");
6 | StringBuffer result=new StringBuffer();
7 | for(String temp :words){
8 | int i=0;
9 | char[] chars=temp.toCharArray();
10 | for(char c:chars){
11 | i++;
12 | }
13 | for(i--;i>=0;i--){
14 | result.append(chars[i]);
15 | }
16 | result.append(" ");
17 | }
18 | result.deleteCharAt(result.length() - 1);
19 | return result.toString();
20 | }
21 | }
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.12.2-leetcode557/莎莎.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution:
3 | def reverseWords(self, s):
4 | """
5 | :type s: str
6 | :rtype: str
7 | """
8 | str1 = ''
9 | list1 = s.split(' ')
10 | for i in list1:
11 | i = i[::-1]
12 | str1 += i + ' '
13 | str1=str1[:-1]
14 | return str1
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.20-leetcode406/406. 根据身高重建队列.md:
--------------------------------------------------------------------------------
1 | 假设有打乱顺序的一群人站成一个队列。
2 | 每个人由一个整数对(h, k)表示,其中h是这个人的身高,k是排在这个人前面且身高大于或等于h的人数。
3 | 编写一个算法来重建这个队列。
4 |
5 | 注意:
6 | 总人数少于1100人。
7 |
8 | 示例
9 |
10 | 输入:
11 | [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]
12 |
13 | 输出:
14 | [[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
15 |
--------------------------------------------------------------------------------
/2018.12.20-leetcode406/Avalon.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int[][] reconstructQueue(int[][] people) {
3 | //按照身高降序,位置升序进行排序
4 | Arrays.sort(people,(x,y)->x[0]==y[0]?x[1]-y[1]:y[0]-x[0]);
5 |
6 | List templist = new LinkedList<>();
7 | for (int[] p :
8 | people) {
9 | templist.add(p[1], p);
10 | }
11 | return templist.toArray(new int[templist.size()][]);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/2018.12.20-leetcode406/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | vector> reconstructQueue(vector>& people) {
5 | vector> result;
6 | sort(people.begin(), people.end(), [](pair a, pair b){
7 | return a.first > b.first || (a.first == b.first && a.second < b.second);
8 | });
9 | for(auto p : people){
10 | result.insert(result.begin()+p.second, p);
11 | }
12 | return result;
13 | }
14 | };
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.20-leetcode406/Sagittarius.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | vector> reconstructQueue(vector>& people) {
5 | auto cmp=[](const pair& p1,const pair& p2)
6 | {return p1.first>p2.first||(p1.first==p2.first&&p1.second> res;
9 | for(auto &p:people)
10 | {
11 | res.insert(res.begin()+p.second,p);
12 | }
13 | return res;
14 | }
15 | };
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.20-leetcode406/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int[][] reconstructQueue(int[][] people) {
4 | Arrays.sort(people, (o1, o2) -> o1[0] != o2[0] ? Integer.compare(o2[0], o1[0]) : Integer.compare(o1[1], o2[1]));
5 | for (int i = 0; i < people.length; ++i) {
6 | int[] p = people[i];
7 | for (int j = i; j > p[1]; --j) {
8 | people[j] = people[j - 1];
9 | }
10 | people[p[1]] = p;
11 | }
12 | return people;
13 | }
14 | }
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.20-leetcode406/神秘的火柴人.md:
--------------------------------------------------------------------------------
1 | ```
2 | bool cmp(pair &p1, pair &p2)
3 | {
4 | return (p1.first>p2.first)||(p1.first==p2.first && p1.second> reconstructQueue(vector>& people) {
10 |
11 | sort(people.begin(), people.end(), cmp);
12 |
13 | vector> ret;
14 | for(auto it:people)
15 | {
16 | ret.insert(ret.begin() + it.second, it);
17 | }
18 |
19 | return ret;
20 | }
21 | };
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.12.21-leetcode763/763. 划分字母区间.md:
--------------------------------------------------------------------------------
1 | 字符串 S 由小写字母组成。我们要把这个字符串划分为尽可能多的片段,同一个字母只会出现在其中的一个片段。
2 | 返回一个表示每个字符串片段的长度的列表。
3 |
4 | 示例 1:
5 |
6 | 输入: S = "ababcbacadefegdehijhklij"
7 | 输出: [9,7,8]
8 | 解释:
9 | 划分结果为 "ababcbaca", "defegde", "hijhklij"。
10 | 每个字母最多出现在一个片段中。
11 | 像 "ababcbacadefegde", "hijhklij" 的划分是错误的,因为划分的片段数较少。
12 | 注意:
13 |
14 | S的长度在[1, 500]之间。
15 | S只包含小写字母'a'到'z'。
16 |
--------------------------------------------------------------------------------
/2018.12.21-leetcode763/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | vector partitionLabels(string S) {
5 | int size = S.length();
6 | map d;
7 | for(int i = 0; i < size; i++) d[S[i]] = i;
8 | int start = 0; int end = 0;
9 | vector res;
10 | for(int i = 0; i < size; i++){
11 | end = end>d[S[i]]?end:d[S[i]];
12 | if(i == end ){
13 | res.push_back(end - start + 1);
14 | start = end + 1;
15 | }
16 | }
17 | return res;
18 | }
19 | };
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.21-leetcode763/WYJ.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public List partitionLabels(String S) {
4 | int[] end = new int[256];
5 | for(int i = 0; i < S.length(); i++){
6 | end[S.charAt(i)] = i;
7 | }
8 | int j = 0, anchor = 0;
9 | List res = new ArrayList<>();
10 | for(int i = 0; i < S.length(); i++){
11 | j = Math.max(j, end[S.charAt(i)]);
12 | if(j == i){
13 | res.add(i - anchor + 1);
14 | anchor = i + 1;
15 | }
16 | }
17 | return res;
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.22-leetcode605/605. 种花问题.md:
--------------------------------------------------------------------------------
1 | 假设你有一个很长的花坛,一部分地块种植了花,另一部分却没有。
2 | 可是,花卉不能种植在相邻的地块上,它们会争夺水源,两者都会死去。
3 |
4 | 给定一个花坛(表示为一个数组包含0和1,其中0表示没种植花,1表示种植了花),和一个数 n 。
5 | 能否在不打破种植规则的情况下种入 n 朵花?能则返回True,不能则返回False。
6 |
7 | 示例 1:
8 |
9 | 输入: flowerbed = [1,0,0,0,1], n = 1
10 | 输出: True
11 | 示例 2:
12 |
13 | 输入: flowerbed = [1,0,0,0,1], n = 2
14 | 输出: False
15 | 注意:
16 |
17 | 数组内已种好的花不会违反种植规则。
18 | 输入的数组长度范围为 [1, 20000]。
19 | n 是非负整数,且不会超过输入数组的大小。
20 |
--------------------------------------------------------------------------------
/2018.12.22-leetcode605/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public boolean canPlaceFlowers(int[] flowerbed, int n) {
4 | int len = flowerbed.length;
5 | if (len < 2 * n - 1) {
6 | return false;
7 | }
8 | for (int i = 0; i < len && n > 0; ) {
9 | int next = i + 1 < len ? flowerbed[i + 1] : 0;
10 | if (flowerbed[i] == 0 && next == 0) {
11 | --n;
12 | i += 2;
13 | } else {
14 | while (++i < len && flowerbed[i] == 1) {}
15 | ++i;
16 | }
17 | }
18 | return n == 0;
19 | }
20 | }
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.12.22-leetcode605/棕榈树.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public boolean canPlaceFlowers(int[] flowerbed, int n) {
4 | int i=0,count = 0;
5 | while(i=n;
14 | }
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.23-leetcode392/392. 判断子序列.md:
--------------------------------------------------------------------------------
1 | 给定字符串 s 和 t ,判断 s 是否为 t 的子序列。
2 |
3 | 你可以认为 s 和 t 中仅包含英文小写字母。字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符串(长度 <=100)。
4 |
5 | 字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。
6 | (例如,"ace"是"abcde"的一个子序列,而"aec"不是)。
7 |
8 | 示例 1:
9 | s = "abc", t = "ahbgdc"
10 |
11 | 返回 true.
12 |
13 | 示例 2:
14 | s = "axc", t = "ahbgdc"
15 |
16 | 返回 false.
17 |
18 | 后续挑战 :
19 |
20 | 如果有大量输入的 S,称作S1, S2, ... , Sk 其中 k >= 10亿,你需要依次检查它们是否为 T 的子序列。
21 | 在这种情况下,你会怎样改变代码?
22 |
--------------------------------------------------------------------------------
/2018.12.23-leetcode392/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | bool isSubsequence(string s, string t) {
5 | int ls = s.length();
6 | int lt = t.length();
7 | int i =0; int j = 0;
8 | for(; i!=ls&&j!=lt;){
9 | if(s[i]==t[j]){
10 | i++;
11 | j++;
12 | }else{
13 | j++;
14 | }
15 | }
16 | if(i==ls) return true;
17 | else return false;
18 | }
19 | };
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.23-leetcode392/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public boolean isSubsequence(String s, String t) {
4 | int index = -1;
5 | for (char c : s.toCharArray()) {
6 | // 每次从下一个位置开始找
7 | index = t.indexOf(c, index + 1);
8 | // 没找到
9 | if (index == -1) {
10 | return false;
11 | }
12 | }
13 | return true;
14 | }
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.23-leetcode392/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```python
2 | class Solution(object):
3 | def isSubsequence(self, s, t):
4 | """
5 | :type s: str
6 | :type t: str
7 | :rtype: bool
8 | """
9 | if len(s) == 0:
10 | return True
11 | if len(s) > len(t):
12 | return False
13 | index = 0
14 | for i in range(len(t)):
15 | if t[i] == s[index]:
16 | index += 1
17 | if index == len(s):
18 | return True
19 | return False
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.23-leetcode392/WYJ.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public boolean isSubsequence(String s, String t) {
4 | if(s.length() == 0){
5 | return true;
6 | }
7 | int indexS = 0, indexT = 0;
8 | while(indexT < t.length()){
9 | if(t.charAt(indexT) == s.charAt(indexS)){
10 | indexS++;
11 | }
12 | indexT++;
13 | if(indexS == s.length()){
14 | return true;
15 | }
16 | }
17 | return false;
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.23-leetcode392/lyan_dut.md:
--------------------------------------------------------------------------------
1 | ```c++
2 | /*
3 | * 392. 判断子序列
4 | * https://leetcode-cn.com/problems/is-subsequence/
5 | */
6 | /*
7 | * 方法一: 双指针
8 | */
9 | bool MyLeetCode::isSubsequence(string s, string t) {
10 | if(s.length()==0 && t.length()==0)
11 | return true;
12 | for(int i=0, j=0; j < t.length(); j++){
13 | if(s[i] == t[j])
14 | i++;
15 | if(i==s.length())
16 | return true;
17 | }
18 | return false;
19 | }
20 |
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.12.23-leetcode392/sourcema.md:
--------------------------------------------------------------------------------
1 | # leetcode 392
2 | class Solution {
3 | public boolean isSubsequence(String s, String t) {//依次比较s和t中的元素是否相等
4 | if (s == null ||t==null) {
5 | return false;
6 | }
7 | if (s.length() == 0) {
8 | return true;
9 | }
10 | int j=0;
11 | for (int i =0; i & nums) {
5 | int size = nums.size();
6 | int res = 0;
7 | for(int i = 1; i < size && res < 2; i++){
8 | if(nums[i]>=nums[i-1]) continue;
9 | if(i-2>=0 && nums[i] nums[i]) {
6 | if(i-2 < 0 || nums[i-2] < nums[i]) {
7 | nums[i-1] = nums[i];
8 | } else {
9 | nums[i] = nums[i-1];
10 | }
11 | cnt++;
12 | }
13 | }
14 | if(cnt <= 1) return true;
15 | return false;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/2018.12.25-leetcode122/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int maxProfit(vector& prices) {
5 | int size = prices.size();
6 | if(size == 0) return 0;
7 | int profit = 0;
8 | for(int i = 1; i < size; i++){
9 | profit += prices[i]>prices[i-1]?prices[i]-prices[i-1]:0;
10 | }
11 | return profit;
12 | }
13 | };
14 | ```
15 |
--------------------------------------------------------------------------------
/2018.12.25-leetcode122/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxProfit(int[] prices) {
4 | int res = 0;
5 | for (int i = 1; i < prices.length; ++i) {
6 | if (prices[i] > prices[i - 1]) {
7 | res += prices[i] - prices[i - 1];
8 | }
9 | }
10 | return res;
11 | }
12 | }
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.25-leetcode122/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```python
2 | class Solution(object):
3 | def maxProfit(self, prices):
4 | """
5 | :type prices: List[int]
6 | :rtype: int
7 | """
8 | profile = 0
9 | for i in range(1, len(prices)):
10 | if prices[i] > prices[i-1]:
11 | profile += prices[i] - prices[i-1]
12 | return profile
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.25-leetcode122/marguerite.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ```
4 | public class OneHundredAndTwentyTwo {
5 |
6 | public static int maxProfit(int[] prices) {
7 | int sum = 0;
8 | for(int i = prices.length - 1;i>0;i--) {
9 | if(prices[i] <= prices[i-1]) {
10 | continue;
11 | } else {
12 | sum += prices[i] - prices[i-1];
13 | }
14 | }
15 | return sum;
16 | }
17 | public static void main(String[] args) {
18 | int[] nums = new int[] {7,6,5,9,1,3};
19 | System.out.println(maxProfit(nums));
20 | }
21 | }
22 |
23 | ```
24 |
--------------------------------------------------------------------------------
/2018.12.25-leetcode122/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 122
2 | class Solution {
3 | public int maxProfit(int[] prices) {//只要有差价就进行交易
4 | if (prices==null||prices.length==0||prices.length==1) {
5 | return 0;
6 | }
7 | int res=0;
8 | for (int i = 0; i < prices.length-1; i++) {
9 | if (prices[i+1]-prices[i]>0) {
10 | res+=prices[i+1]-prices[i];
11 | }
12 | }
13 | return res;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/2018.12.25-leetcode122/利爪德鲁伊.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int maxProfit(int[] prices) {
3 | int res = 0;
4 | for(int i = 1; i < prices.length; i++){
5 | if(prices[i] > prices[i-1]){
6 | res += prices[i] - prices[i-1];
7 | }
8 | }
9 | return res;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/2018.12.25-leetcode122/句子.md:
--------------------------------------------------------------------------------
1 | ```c++
2 | class Solution {
3 | public:
4 | int maxProfit(vector& prices) {
5 | int get=0;
6 | for(int i=1;iprices[i-1])
8 | get+=prices[i]-prices[i-1];
9 | }
10 | return get;
11 | }
12 | };
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.25-leetcode122/棕榈树.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int maxProfit(int[] prices) {
4 | int profit = 0;
5 | boolean buy = false;
6 | for(int i=0;i& nums) {
5 | int size = nums.size();
6 | vector dp(size+1);
7 | dp[0] = nums[0];
8 | int ans = nums[0];
9 | for(int i = 1; i0) dp[i]=nums[i]+dp[i-1];
11 | else dp[i] = nums[i];
12 | ans = max(ans,dp[i]);
13 | }
14 | return ans;
15 | }
16 | };
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.12.26-leetcode53/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxSubArray(int[] nums) {
4 | int maxSum = nums[0];
5 | int curSum = nums[0];
6 | for (int i = 1; i < nums.length; ++i) {
7 | curSum = curSum > 0 ? curSum + nums[i] : nums[i];
8 | maxSum = Math.max(maxSum, curSum);
9 | }
10 | return maxSum;
11 | }
12 | }
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.26-leetcode53/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxSubArray(int[] nums) {
4 | int [] n = new int[nums.length];
5 | n[0] = nums[0];
6 | for (int i = 1; i < nums.length; i++){
7 | nums[i] = (nums[i] + nums[i-1]) < nums[i]? nums[i]: (nums[i] + nums[i-1]);
8 | }
9 | int max = nums[0];
10 | for (int i = 1; i < nums.length; i++){
11 | max = nums[i] > max? nums[i]: max;
12 | }
13 | return max;
14 | }
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.26-leetcode53/marguerite.md:
--------------------------------------------------------------------------------
1 | ###求和,然后判断和是否小于0,
2 |
3 | ###因为只要前面的和小于0,那么后面的数加上前面的和就一定比自身小,所以又重新求和,
4 |
5 | ###并和之前的最大子序和比较,取最大值。
6 |
7 |
8 | ```
9 |
10 | class Solution {
11 | public:
12 | int maxSubArray(vector& nums) {
13 | int ans = 0, maxn = INT_MIN;
14 | int len = nums.size();
15 | for(int i = 0; i < len; i++){
16 | if(ans < 0) ans = 0; //如果前面的和小0,那么重新开始求和
17 | ans += nums[i];
18 | maxn = max(maxn, ans);
19 | }
20 | return maxn;
21 | }
22 |
23 |
24 | ```
25 |
--------------------------------------------------------------------------------
/2018.12.26-leetcode53/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 53
2 | class Solution {
3 | public int maxSubArray(int[] nums) {//简单的dp思想,如果累加和<0,保存最大值,重新进行累加
4 | if (nums == null || nums.length == 0) {
5 | return 0;
6 | }
7 | int sum=0,max=Integer.MIN_VALUE;
8 | for (int i = 0; i < nums.length; i++) {
9 | sum += nums[i];
10 | max = Math.max(sum, max);
11 | sum=sum<0?0:sum;
12 | }
13 | return max;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/2018.12.26-leetcode53/刘润泽(capture).md:
--------------------------------------------------------------------------------
1 | ```java
2 | /**
3 | * 时间复杂度为O(n)
4 | **/
5 | public static int maxSubArray(int[] nums) {
6 |
7 | int maxSubArray=nums[0];
8 | int tempSubArray=nums[0];
9 |
10 | for (int i=1;imaxSubArray)maxSubArray=tempSubArray;
18 | if (i==nums.length-1) return maxSubArray;
19 |
20 | }
21 |
22 | return maxSubArray;
23 | }
24 | ```
25 |
--------------------------------------------------------------------------------
/2018.12.26-leetcode53/利爪德鲁伊.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int maxSubArray(int[] nums) {
3 | int res = Integer.MIN_VALUE;
4 | int max = 0;
5 | for(int i = 0; i < nums.length; i++){
6 | if(max > 0) {
7 | max += nums[i];
8 | }else{
9 | max = nums[i];
10 | }
11 | if(res < max) res = max;
12 | }
13 | return res;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/2018.12.27-leetcode121/121. 买卖股票的最佳时机.md:
--------------------------------------------------------------------------------
1 | ```
2 | 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。
3 |
4 | 如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润。
5 |
6 | 注意你不能在买入股票前卖出股票。
7 |
8 | 示例 1:
9 |
10 | 输入: [7,1,5,3,6,4]
11 | 输出: 5
12 | 解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。
13 | 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格。
14 | 示例 2:
15 |
16 | 输入: [7,6,4,3,1]
17 | 输出: 0
18 | 解释: 在这种情况下, 没有交易完成, 所以最大利润为 0。
19 | ```
20 |
--------------------------------------------------------------------------------
/2018.12.27-leetcode121/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int maxProfit(vector& prices) {
5 | int ans = 0;
6 | int size = prices.size();
7 | if(size==0) return 0;
8 | int minn = prices[0];
9 | for(int i = 1; i < size; i++){
10 | ans = ans > prices[i]-minn ? ans : prices[i]-minn;
11 | minn = minn > prices[i] ? prices[i] : minn;
12 | }
13 | return ans;
14 | }
15 | };
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.27-leetcode121/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxProfit(int[] prices) {
4 | if (prices == null || prices.length <= 1) {
5 | return 0;
6 | }
7 | int res = 0;
8 | int minPrice = prices[0];
9 | for (int price : prices) {
10 | minPrice = Math.min(minPrice, price);
11 | res = Math.max(res, price - minPrice);
12 | }
13 | return res;
14 | }
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2018.12.27-leetcode121/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxProfit(int[] prices) {
4 | int maxn = 0;
5 | int minn = 100000;
6 | int dest = 0;
7 | for(int i = 0; i < prices.length; i++){
8 | minn = minn < prices[i]? minn: prices[i];
9 | maxn = prices[i];
10 | dest = maxn-minn > dest? maxn-minn: dest;
11 | }
12 | return dest;
13 | }
14 | }
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.27-leetcode121/marguerite.md:
--------------------------------------------------------------------------------
1 |
2 | ###遇到临时最小的,就保存(1),计算后面比它大的差,
3 |
4 | ###保留最大(6-1),遇到后面如果有更小的(0),就保存(0),重复上面工作即可。
5 |
6 | ```
7 |
8 |
9 | public int maxProfit2(int[] prices) {
10 | if(prices==null||prices.length<=1){
11 | return 0;
12 | }
13 | int res=0,temp,inv;
14 | temp=prices[0];
15 | for(int i=1;iinv){
18 | temp=inv;
19 | }else{
20 | inv=inv-temp;
21 | res=res>inv?res:inv;
22 | }
23 | }
24 | return res;
25 |
26 |
27 | ```
28 |
--------------------------------------------------------------------------------
/2018.12.27-leetcode121/刘润泽(capture).md:
--------------------------------------------------------------------------------
1 | ```java
2 | public int maxProfit(int[] prices) {
3 |
4 | int maxProfit=0;
5 | int tempProfit=0;
6 |
7 | for (int i=1;i0){
9 | tempProfit=tempProfit+(prices[i]-prices[i-1]);
10 | if(tempProfit>maxProfit) maxProfit=tempProfit;
11 | }else{
12 | tempProfit=0;}
13 | }
14 |
15 | return maxProfit;
16 | }
17 |
18 | ```
19 |
--------------------------------------------------------------------------------
/2018.12.27-leetcode121/利爪德鲁伊.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int maxProfit(int[] prices) {
3 | int res = 0;
4 | int max = 0;
5 | for(int i = 1; i < prices.length; i++){
6 | if(max > 0){
7 | max += prices[i] - prices[i-1];
8 | } else {
9 | max = prices[i] - prices[i-1];
10 | }
11 | if(res < max) res = max;
12 | }
13 | return res;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/2018.12.28-leetcode69/69. x 的平方根.md:
--------------------------------------------------------------------------------
1 | ```
2 | 实现 int sqrt(int x) 函数。
3 |
4 | 计算并返回 x 的平方根,其中 x 是非负整数。
5 |
6 | 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。
7 |
8 | 示例 1:
9 |
10 | 输入: 4
11 | 输出: 2
12 | 示例 2:
13 |
14 | 输入: 8
15 | 输出: 2
16 | 说明: 8 的平方根是 2.82842...,
17 | 由于返回类型是整数,小数部分将被舍去。
18 | ```
19 |
--------------------------------------------------------------------------------
/2018.12.28-leetcode69/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int mySqrt(int x) {
4 | long r = x;
5 | while (r * r > x) {
6 | r = (r + x / r) / 2;
7 | }
8 | return (int) r;
9 | }
10 | }
11 | ```
12 |
--------------------------------------------------------------------------------
/2018.12.28-leetcode69/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int mySqrt(int x) {
4 | if (x == 0) {
5 | return 0;
6 | }
7 | if (x == 1) {
8 | return 1;
9 | }
10 | int low = 0;
11 | int high = x/2 + 1;
12 | while (low <= high){
13 | int mid = (low + high) / 2;
14 | if (mid < x/mid){
15 | low = mid + 1;
16 | }
17 | else if (mid> x/mid){
18 | high=mid-1;
19 | }
20 | else{
21 | return mid;
22 | }
23 | }
24 | return low-1;
25 | }
26 | }
27 | ```
28 |
--------------------------------------------------------------------------------
/2018.12.28-leetcode69/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 69
2 | class Solution {
3 | public int mySqrt(int n) {
4 | if (n == 0) {
5 | return 0;
6 | }
7 | if (n == 1) {
8 | return 1;
9 | }
10 | int left=0;
11 | int right=n;
12 | while (left<=right) {
13 | int mid=(left+right)/2;
14 | if (mid < n/mid) {
15 | left=mid+1;
16 | } else if (mid> n/mid) {
17 | right=mid-1;
18 | } else {
19 | return mid;
20 | }
21 | }
22 | return left-1;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/2018.12.28-leetcode69/利爪德鲁伊.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int mySqrt(int x) {
3 | if(x == 0) return 0;
4 | int low=1;
5 | int hi=x/2+1;
6 | while(low+1x/mid){
9 | hi=mid;
10 | }
11 | else if(mid& letters, char target) {
10 | int index = upper_bound(letters.begin(),letters.end(),target)-letters.begin();
11 | if(index == letters.size()) index = 0;
12 | return letters[index];
13 | }
14 | };
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.29-leetcode744/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public char nextGreatestLetter(char[] letters, char target) {
4 | int lo = 0;
5 | int hi = letters.length;
6 | while (lo < hi) {
7 | int mid = lo + (hi - lo) / 2;
8 | if (target >= letters[mid]) {
9 | lo = mid + 1;
10 | } else {
11 | hi = mid;
12 | }
13 | }
14 | return lo == letters.length ? letters[0] : letters[lo];
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.12.29-leetcode744/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```python
2 | class Solution(object):
3 | def nextGreatestLetter(self, letters, target):
4 | """
5 | :type letters: List[str]
6 | :type target: str
7 | :rtype: str
8 | """
9 | for x in letters:
10 | if x >target:
11 | return x
12 | return letters[0]
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.29-leetcode744/WYJ.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public char nextGreatestLetter(char[] letters, char target) {
4 |
5 | int distance = Integer.MAX_VALUE;
6 | int index = -1;
7 | for(int i = 0; i < letters.length; i++){
8 | int tempDis = (int)(letters[i] - target);
9 | if(tempDis < 0){
10 | tempDis += 26;
11 | }
12 | if(tempDis > 0&&tempDis < distance){
13 | distance = tempDis;
14 | index = i;
15 | }
16 | }
17 | return letters[index];
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.29-leetcode744/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 744
2 | class Solution {
3 | public char nextGreatestLetter(char[] letters, char target) {//简单的二分思路
4 | //test
5 | int left=0;
6 | int right=letters.length-1;
7 | while(left<=right){
8 | int mid=(left+right)>>1;
9 | if(letters[mid]>target){
10 | right=mid-1;
11 | }else {
12 | left=mid+1;
13 | }
14 | }
15 | return letters[left%letters.length];
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/2018.12.29-leetcode744/利爪德鲁伊.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public char nextGreatestLetter(char[] letters, char target) {
3 | int i = 0;
4 | while(i < letters.length && letters[i++] <= target);
5 | if(i == letters.length && letters[i-1] <= target) return letters[0];
6 | return letters[i-1];
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/Avalon.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int lengthOfLastWord(String s) {
3 | String[] sArr = s.trim().split(" ");
4 | if (sArr.length == 0)
5 | return 0;
6 | return sArr[sArr.length-1].length();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/FFFro.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int lengthOfLastWord(String s) {
3 | String[] s1 = s.split(" ");
4 | if (s1.length == 0)
5 | return 0;
6 | return s1[s1.length-1].length();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/Felix.md:
--------------------------------------------------------------------------------
1 | ```javascript
2 | package leetcode.easy;
3 | /**
4 | * @author Felix
5 | * @date 2018年11月17日下午10:52:33
6 | @version 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。
7 | 如果不存在最后一个单词,请返回 0 。
8 | 说明:一个单词是指由字母组成,但不包含任何空格的字符串。
9 | 示例:输入: "Hello World" 输出: 5
10 | */
11 | public class LengthOfLastWord {
12 | public int lengthOfLastWord(String s) {
13 | if(s == null || s.trim().length() == 0)
14 | return 0;
15 | String[] str = s.split(" ");
16 | String res = str[str.length-1];
17 |
18 | return res.length();
19 | }
20 | }
21 |
22 | ```
23 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/GatesMa.md:
--------------------------------------------------------------------------------
1 | # c++
2 | ```cpp
3 | class Solution {
4 | public:
5 | int lengthOfLastWord(string s) {
6 | stringstream ss;
7 | ss << s;
8 | string str;
9 | while(ss){
10 | ss >> str;
11 | }
12 | return str.length();
13 | }
14 | };
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/Istroyforever.md:
--------------------------------------------------------------------------------
1 | //leetcode off 58
2 | class Solution {
3 | public:
4 | int lengthOfLastWord(string s) {
5 | if(s.size()==0) return 0;
6 | int i=s.size()-1;
7 | while(i>=0 && s[i]==' '){
8 | i--;
9 | }
10 | int count=0;
11 | while(i>=0 && (s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')){
12 | i--;
13 | count++;
14 | }
15 | return count;
16 |
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int lengthOfLastWord(string s) {
5 | while(s[s.length()-1]==' ') s.pop_back();
6 | s.insert(s.begin(),' ');
7 | reverse(s.begin(),s.end());
8 | int len = 0;
9 | for(int i = 0; i < s.length(); i++)
10 | {
11 | while(s[i]!=' ')
12 | {
13 | len++;
14 | i++;
15 | }
16 | break;
17 | }
18 | return len;
19 | }
20 | };
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/Sagittarius.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int lengthOfLastWord(string s) {
5 | int len=s.size();
6 | char space=' ';
7 | int i=len-1;
8 | while(i>=0)
9 | {
10 | if(s[i]==space)
11 | i--;
12 | else
13 | break;
14 | }
15 | if(i==-1)
16 | return 0;
17 | else
18 | {
19 | len=i;
20 | while(i>=0&&s[i]!=space)
21 | i--;
22 | }
23 | return len-i;
24 | }
25 | };
26 | ```
27 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/Sunny.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int lengthOfLastWord(String s) {
4 | if (s == null) return 0;
5 | int i = s.lastIndexOf(" ");
6 | if (i < 0) return s.length();
7 | if (i == (s.length() - 1) && s.length() > 1) {
8 | s = s.substring(0, i);
9 | return lengthOfLastWord(s);
10 | }
11 | return s.substring(i+1, s.length()).length();
12 | }
13 | }
14 | ```
15 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int lengthOfLastWord(String s) {
4 | int res = 0;
5 | int i = s.length() - 1;
6 | for (; i >= 0 && s.charAt(i) == ' '; --i);
7 | for (; i >= 0 && s.charAt(i) != ' '; --i) {
8 | ++res;
9 | }
10 | return res;
11 | }
12 | }
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/WhiteNight.md:
--------------------------------------------------------------------------------
1 | >```java
2 | >/**
3 | > * leetcode58 最后一个单词的长度
4 | > *
5 | > */
6 | >public class S5 {
7 | > public int lengthOfLastWord(String s) {
8 | > String[] string = s.split(" ");
9 | > if (string == null || string.length == 0)
10 | > return 0;
11 | > int i = string.length - 1;
12 | > return string[i].length();
13 | > }
14 | >
15 | > public static void main(String[] args) {
16 | > S5 s = new S5();
17 | > String string = "Hello World";
18 | > int res = s.lengthOfLastWord(string);
19 | > System.out.println(res);
20 | > }
21 | >}
22 | >```
23 |
24 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/disappo1nted.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int lengthOfLastWord(String s) {
3 | String[] res=s.split(" ");
4 | if(res.length==0)
5 | return 0;
6 | else
7 | return res[res.length-1].length();
8 |
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/fish.md:
--------------------------------------------------------------------------------
1 | >给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。
2 | >如果不存在最后一个单词,请返回 0 。
3 | >说明:一个单词是指由字母组成,但不包含任何空格的字符串。
4 |
5 | ```
6 | public static int lengthOfLastWord(String str){
7 | String trim = str.trim();
8 | if (str.matches("[a-zA-Z ]*") && !trim.isEmpty()) {
9 | int index = trim.lastIndexOf(' ');
10 | return index < 0 ? trim.length() : trim.length() - index - 1;
11 | }
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/halfofwater.md:
--------------------------------------------------------------------------------
1 | ## LeetCode 58
2 |
3 | ``` C++
4 | class Solution {
5 | public:
6 | int lengthOfLastWord(string s) {
7 |
8 | stringstream input(s);
9 | string word;
10 | vector vec;
11 | while (input >> word) {
12 | vec.push_back(word);
13 | }
14 | if (vec.size() != 0)
15 | return vec[vec.size() - 1].size();
16 | else
17 | return 0;
18 |
19 | }
20 | };
21 | ```
22 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/kiritocly.md:
--------------------------------------------------------------------------------
1 | private static int solution(String input) {
2 | String[] splits = input.split(" ");
3 | if (splits.length == 0) {
4 | return 0;
5 | }
6 | return splits[splits.length - 1].length();
7 | }
8 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 58
2 | class Solution {
3 | public int lengthOfLastWord(String s) {
4 | if (s == null || s.length() == 0) {
5 | return 0;
6 | }
7 | String str = s.trim();
8 | int length=0;
9 | for (int i=str.length()-1;i>=0;i--) {
10 | if (str.charAt(i) != ' ') {
11 | length++;
12 | } else {
13 | break;
14 | }
15 | }
16 | return length;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/tongLuoWan.md:
--------------------------------------------------------------------------------
1 | ```
2 | public class Solution {
3 | public int lengthOfLastWord(String s) {
4 | String[] tt;
5 | tt = s.split(" ");
6 | return tt.length == 0?0:tt[tt.length-1].length();
7 | }
8 | }
9 | ```
10 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/zjukk.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int lengthOfLastWord(string s) {
5 | istringstream is(s);
6 | string tmp;
7 | while (is >> tmp);
8 | return tmp.size();
9 | }
10 | };
11 | ```
12 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/。V1ncentzzZ.md:
--------------------------------------------------------------------------------
1 |
2 | 58. 最后一个单词的长度 https://leetcode-cn.com/problems/length-of-last-word/
3 |
4 | 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。
5 |
6 | 如果不存在最后一个单词,请返回 0 。
7 |
8 | 说明:一个单词是指由字母组成,但不包含任何空格的字符串。
9 |
10 | 示例:
11 |
12 | 输入: "Hello World"
13 | 输出: 5
14 |
15 |
16 | class Solution {
17 | public int lengthOfLastWord(String s) {
18 | s = s.trim();
19 | int result = 0;
20 | if("".equals(s)) return result;
21 | if(!s.contains(" ")) return s.length();
22 | for(int i = s.lastIndexOf(" ")+1; i= 0; i--){
5 | if (s.charAt(i) == ' '){
6 | if (result == 0)continue;
7 | break;
8 | }
9 | result++;
10 | }
11 | return result;
12 | }
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/云深不叹.md:
--------------------------------------------------------------------------------
1 | ```
2 | public int lengthOfLastWord(String s) {
3 | if(s==null || s.trim().equals("")){
4 | return 0;
5 | }
6 | String[] arr = s.split(" ");
7 | return arr[arr.length-1].length();
8 | }
9 | ```
10 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/啦啦啦.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int lengthOfLastWord(String s) {
4 | if(s==null||s.length()==0)return 0;
5 | int res=0;
6 | int i=s.length()-1;
7 | while(i>=0&&s.charAt(i)==' ')i--;
8 | for(;i>=0;i--){
9 | if(s.charAt(i)!=' '){
10 | res++;
11 | }
12 | else break;
13 | }
14 | return res;
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/大魔王爱穿孖烟筒.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int lengthOfLastWord(String s) {
4 | String [] list = s.split(" ");//定义字符串数组,以空格来分割字符串
5 | if(list.length == 0)//字符串长度是0直接返回
6 | return 0;
7 | return list[list.length-1].length();//返回最后一个字符串的长度
8 | }
9 | }
10 | ```
11 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/家:
--------------------------------------------------------------------------------
1 | ```
2 | func lengthOfLastWord(s string) int {
3 | l := len(s)
4 | i := l-1
5 | count := 0
6 | for ;i>=0 && s[i] == ' ';i--{}
7 | for ;i>=0 && s[i] != ' ';i--{count++}
8 | return count
9 | }
10 |
11 | ```
12 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/张小胖.md:
--------------------------------------------------------------------------------
1 | class Solution{
2 | public:
3 | int lengthOfLastWorld(string s){
4 | int slength=s.size();
5 | int i=slength-1,length=0;
6 | if(s.size()==0)return 0;
7 | for(i;i>=0;i--)
8 | {
9 | if(s[i]!=' ')
10 | {
11 | break;
12 | }
13 | }
14 | for(i;s[i]!=' '&&i>=0;i--)
15 | {
16 | length++;
17 | }
18 | return length;
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/我爱吃瓜子.md:
--------------------------------------------------------------------------------
1 | #leetcode 58
2 | ```
3 | class Solution {
4 | public int lengthOfLastWord(String s) {
5 | String[] ss=s.split(" ");
6 | int index=0;
7 | if(ss.length>0){
8 | index=ss[ss.length-1].length();
9 |
10 | }
11 | return index;
12 | }
13 | }
14 | ```
15 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/最后一个单词的长度.md:
--------------------------------------------------------------------------------
1 | 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。
2 |
3 | 如果不存在最后一个单词,请返回 0 。
4 |
5 | 说明:一个单词是指由字母组成,但不包含任何空格的字符串。
6 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/李碧涵.md:
--------------------------------------------------------------------------------
1 | #### [58. Length of Last Word](https://leetcode.com/problems/length-of-last-word/)
2 | **题目描述**
3 | > 给定一个只包含大小写字母或空字符的字符串s,返回字符串中最后一个单词的长度。如果最后一个单词不存在,返回0。
4 |
5 | > 单词 - 只包含非空格字符的字符序列。
6 |
7 | **例子**
8 | > Input: "Hello World"
9 | Output: 5
10 |
11 | **思想**
12 | 比较简单。注意:当s只包含空格时的情况
13 | **解法**
14 | ```python
15 | class Solution(object):
16 | def lengthOfLastWord(self, s):
17 | """
18 | :type s: str
19 | :rtype: int
20 | """
21 | s = s.split()
22 | if not s:
23 | return 0
24 | return len(s[-1])
25 | ```
26 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/杨.md:
--------------------------------------------------------------------------------
1 | ```
2 | public int firstUniqChar(String s) {
3 | int res = -1;
4 | for(char i ='a';i<='z';i++){
5 | int index = s.indexOf(i);
6 | if(index!=-1 && index == s.lastIndexOf(i)){
7 | res = (res==-1 || res > index) ? index : res;
8 | }
9 | }
10 | return res;
11 | }
12 |
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/湛江甲鸟.md:
--------------------------------------------------------------------------------
1 | ```
2 | public int lengthOfLastWord(String s) {
3 | if (s == null || s.length() == 0){
4 | return 0;
5 | }
6 | String[] strs = s.split(" ");
7 | int last = strs.length - 1;
8 | return strs[last].length();
9 | }
10 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/神秘的火柴人.md:
--------------------------------------------------------------------------------
1 | ```
2 |
3 |
4 | class Solution {
5 | public:
6 | int lengthOfLastWord(string s) {
7 | int end = s.length()-1;
8 | while(s[end] == ' ')
9 | end--;
10 |
11 | int ret = 0;
12 | while(end>=0 && s[end]!=' ')
13 | {
14 | end--;
15 | ret++;
16 | }
17 |
18 | return ret;
19 | }
20 | };
21 |
22 |
23 | ```
24 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/莎莎.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution:
3 | def lengthOfLastWord(self, s):
4 | """
5 | :type s: str
6 | :rtype: int
7 | """
8 | list1 = s.strip().split(' ')
9 | last = list1[-1]
10 | return len(last)
11 | ```
12 |
13 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/阳.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int lengthOfLastWord(String s) {
3 | int len = 0;
4 | //空格串trim掉为空字符串
5 | s = s.trim();
6 | if(s == ""){
7 | len = 0;
8 | }else{
9 | char[] chs = s.toCharArray();
10 | int i = chs.length - 1;
11 | while(i >= 0&&chs[i] != ' '){
12 | i--;
13 | len++;
14 | }
15 | }
16 | return len;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/2018.12.3-leetcode58/青衫忆笙.md:
--------------------------------------------------------------------------------
1 | class LeetCode58 {
2 |
3 | public int lengthOfLastWord(String s) {
4 | if(s==null||s.length()==0) {
5 | return 0;
6 | }
7 | char[] ch=s.toCharArray();
8 | int i;
9 | for(i=ch.length-1;i>=0&&ch[i]==' ';i--);
10 | int j=i;
11 | for(;j>=0&&ch[j]!=' ';j--);
12 | return i-j;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/2018.12.30-leetcode540/540. 有序数组中的单一元素.md:
--------------------------------------------------------------------------------
1 | ```
2 | 给定一个只包含整数的有序数组,每个元素都会出现两次,唯有一个数只会出现一次,找出这个数。
3 |
4 | 示例 1:
5 |
6 | 输入: [1,1,2,3,3,4,4,8,8]
7 | 输出: 2
8 | 示例 2:
9 |
10 | 输入: [3,3,7,7,10,11,11]
11 | 输出: 10
12 | 注意: 您的方案应该在 O(log n)时间复杂度和 O(1)空间复杂度中运行。
13 | ```
14 |
--------------------------------------------------------------------------------
/2018.12.30-leetcode540/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int singleNonDuplicate(int[] nums) {
4 | int lo = 0;
5 | int hi = nums.length - 1;
6 | while (lo < hi) {
7 | int mid = lo + (hi - lo) / 2;
8 | if ((mid & 1) == 1) {
9 | --mid;
10 | }
11 | if (nums[mid] == nums[mid + 1]) {
12 | lo = mid + 2;
13 | } else {
14 | hi = mid;
15 | }
16 | }
17 | return nums[lo];
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.30-leetcode540/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```python
2 | class Solution(object):
3 | def singleNonDuplicate(self, nums):
4 | """
5 | :type nums: List[int]
6 | :rtype: int
7 | """
8 | cot = 1
9 | pre = nums[0]
10 | for i in range(1, len(nums), 1):
11 | if nums[i] == pre:
12 | cot += 1
13 | else:
14 | if cot == 1:
15 | return pre
16 | else:
17 | pre = nums[i]
18 | cot = 1
19 | return nums[-1]
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.30-leetcode540/sourcema.md:
--------------------------------------------------------------------------------
1 | # leetcode 540
2 | class Solution {
3 | public int singleNonDuplicate(int[] nums) {
4 | int start = 0, end = nums.length - 1;
5 | while (start < end) {
6 | int mid=(start+end)>>1;
7 | if ((mid&1)==1) mid--;
8 | if ( nums[mid] == nums[mid + 1]) {
9 | start = mid + 2;//如果mid是--之后的值,mid+1 mid可能又回到原来的值可能造成死循环
10 | } else if ( mid-1>=0&&nums[mid] == nums[mid - 1]) {
11 | end=mid-1;
12 | } else {
13 | return nums[mid];
14 | }
15 | }
16 | return nums[start];
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/2018.12.30-leetcode540/棕榈树.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int singleNonDuplicate(int[] nums) {
4 | int start = 0;
5 | int end = nums.length - 1;
6 | while(start false
15 | 调用 isBadVersion(5) -> true
16 | 调用 isBadVersion(4) -> true
17 |
18 | 所以,4 是第一个错误的版本。
19 | ```
20 |
--------------------------------------------------------------------------------
/2018.12.31-leetcode278/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | // Forward declaration of isBadVersion API.
3 | bool isBadVersion(int version);
4 |
5 | class Solution {
6 | public:
7 | int firstBadVersion(int n) {
8 | int l = 1, r = n;
9 | int mid;
10 | while(l<=r){
11 | mid = l + (r-l)/2;
12 | if(isBadVersion(mid)) r = mid - 1;
13 | else l = mid + 1;
14 | }
15 | return l;
16 | }
17 | };
18 | ```
19 |
--------------------------------------------------------------------------------
/2018.12.31-leetcode278/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | /* The isBadVersion API is defined in the parent class VersionControl.
3 | boolean isBadVersion(int version); */
4 |
5 | public class Solution extends VersionControl {
6 | public int firstBadVersion(int n) {
7 | int lo = 1;
8 | int hi = n;
9 | while (lo < hi) {
10 | int mid = lo + (hi - lo) / 2;
11 | if (isBadVersion(mid)) {
12 | hi = mid;
13 | } else {
14 | lo = mid + 1;
15 | }
16 | }
17 | return lo;
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2018.12.31-leetcode278/WYJ.md:
--------------------------------------------------------------------------------
1 | ```java
2 | public class Solution extends VersionControl {
3 | public int firstBadVersion(int n) {
4 | int l = 1, r = n;
5 | while(l < r){
6 | int mid = l + (r - l) / 2;
7 | if(isBadVersion(mid)){
8 | r = mid;
9 | }
10 | else{
11 | l = mid + 1;
12 | }
13 | }
14 | return l;
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2018.12.31-leetcode278/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 278
2 | public class Solution extends VersionControl {
3 | public int firstBadVersion(int n) {
4 | int left=1;
5 | int right=n;
6 | while(leftleft,root->right);
7 | }
8 | bool help(TreeNode* left, TreeNode* right) {
9 | if (!left && !right) return true;
10 | if ((!left && right) || (left && !right)) return false;
11 | if (left->val != right->val) return false;
12 | else return help(left->left,right->right) && help(left->right,right->left);
13 | }
14 | };
15 | ```
16 |
--------------------------------------------------------------------------------
/2018.12.4-leetcode101/家.md:
--------------------------------------------------------------------------------
1 | ```
2 | func isSymmetric(root *TreeNode) bool {
3 | return isw(root,root)
4 | }
5 | func isw (left *TreeNode,right *TreeNode) bool{
6 | if left == nil && right == nil {return true}
7 | if left == nil || right == nil{return false}
8 | return left.Val == right.Val && isw(left.Left,right.Right)&&isw(left.Right,right.Left)
9 | }
10 |
11 | ```
12 |
--------------------------------------------------------------------------------
/2019.01.01-leetcode153/153.旋转数组的最小数字.md:
--------------------------------------------------------------------------------
1 | ```
2 | 假设按照升序排序的数组在预先未知的某个点上进行了旋转。
3 |
4 | ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。
5 |
6 | 请找出其中最小的元素。
7 |
8 | 你可以假设数组中不存在重复元素。
9 |
10 | 示例 1:
11 |
12 | 输入: [3,4,5,1,2]
13 | 输出: 1
14 | 示例 2:
15 |
16 | 输入: [4,5,6,7,0,1,2]
17 | 输出: 0
18 | ```
19 |
--------------------------------------------------------------------------------
/2019.01.01-leetcode153/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int findMin(vector& nums) {
5 | int l = 0;
6 | int r = nums.size()-1;
7 | int mid = 0;
8 | while(l>1;
11 | if(nums[mid]>nums[r]) l = mid+1;
12 | else r = mid;
13 | }
14 | return nums[r];
15 | }
16 | };
17 | ```
18 |
--------------------------------------------------------------------------------
/2019.01.01-leetcode153/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int findMin(int[] nums) {
4 | int lo = 0;
5 | int hi = nums.length - 1;
6 | while (lo < hi) {
7 | int mid = lo + (hi - lo) / 2;
8 | if (nums[mid] > nums[hi]) {
9 | lo = mid + 1;
10 | } else {
11 | hi = mid;
12 | }
13 | }
14 | return nums[lo];
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2019.01.01-leetcode153/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```python
2 | class Solution(object):
3 | def findMin(self, nums):
4 | """
5 | :type nums: List[int]
6 | :rtype: int
7 | """
8 | return min(nums)
9 | ```
10 |
--------------------------------------------------------------------------------
/2019.01.01-leetcode153/WYJ.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int findMin(int[] nums) {
4 | int l = 0, r = nums.length - 1;
5 | while(l < r){
6 | int mid = l + (r - l) / 2;
7 | if(nums[mid] > nums[r]){
8 | l = mid + 1;
9 | }
10 | else{
11 | r = mid;
12 | }
13 | }
14 | return nums[l];
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2019.01.01-leetcode153/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 153
2 | class Solution {
3 | public int findMin(int[] nums) {//典型的二分,数组进行了旋转,我们现在把数组分为两部分,
4 | // 前面部分是数组中元素较大的元素,后面部分呢是数组中元素较小的元素,如果中间部分的元素值大于首元素和
5 | //末尾元素说明当前位置在数组的前半部分,left应该等于mid+1,否则说明在数组后半部分right==mid;
6 | int left=0;
7 | int right=nums.length-1;
8 | while (left < right && nums[left] > nums[right]) {
9 | int mid=(left+right)>>1;
10 | if (nums[mid] >= nums[left] && nums[right] < nums[mid]) {
11 | left = mid + 1;
12 | } else {
13 | right=mid;
14 | }
15 | }
16 | return nums[left];
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/2019.01.01-leetcode153/神秘的火柴人.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int findMin(vector& nums) {
5 | if(nums.size() <= 1) return nums[0];
6 |
7 | int i = 0;
8 | int j = 1;
9 | while(j < nums.size())
10 | {
11 | if(nums[i] > nums[j])
12 | return nums[j];
13 | i++;
14 | j++;
15 | }
16 |
17 | return nums[0];
18 | }
19 | };
20 | ```
21 |
--------------------------------------------------------------------------------
/2019.01.02-leetcode34/Tony the Cyclist.md:
--------------------------------------------------------------------------------
1 | ```python
2 | class Solution(object):
3 | def searchRange(self, nums, target):
4 | """
5 | :type nums: List[int]
6 | :type target: int
7 | :rtype: List[int]
8 | """
9 | if target not in nums:
10 | return [-1, -1]
11 | begin = nums.index(target)
12 | nums.reverse()
13 | end = len(nums) - 1 - nums.index(target)
14 | return [begin, end]
15 | ```
16 |
--------------------------------------------------------------------------------
/2019.01.02-leetcode34/在排序数组中查找元素的第一个和最后一个位置.md:
--------------------------------------------------------------------------------
1 | 给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。
2 |
3 | 你的算法时间复杂度必须是 O(log n) 级别。
4 |
5 | 如果数组中不存在目标值,返回 [-1, -1]。
6 |
7 | 示例 1:
8 |
9 | 输入: nums = [5,7,7,8,8,10], target = 8
10 | 输出: [3,4]
11 | 示例 2:
12 |
13 | 输入: nums = [5,7,7,8,8,10], target = 6
14 | 输出: [-1,-1]
15 |
--------------------------------------------------------------------------------
/2019.01.03-leetcode241/为运算表达式设计优先级:
--------------------------------------------------------------------------------
1 | 给定一个含有数字和运算符的字符串,为表达式添加括号,改变其运算优先级以求出不同的结果。你需要给出所有可能的组合的结果。有效的运算符号包含 +, - 以及 * 。
2 |
3 | 示例 1:
4 |
5 | 输入: "2-1-1"
6 | 输出: [0, 2]
7 | 解释:
8 | ((2-1)-1) = 0
9 | (2-(1-1)) = 2
10 | 示例 2:
11 |
12 | 输入: "2*3-4*5"
13 | 输出: [-34, -14, -10, -10, 10]
14 | 解释:
15 | (2*(3-(4*5))) = -34
16 | ((2*3)-(4*5)) = -14
17 | ((2*(3-4))*5) = -10
18 | (2*((3-4)*5)) = -10
19 | (((2*3)-4)*5) = 10
20 |
--------------------------------------------------------------------------------
/2019.01.04-leetcode279/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int numSquares(int n) {
5 | vector dp;
6 | dp.push_back(0);
7 | for(int i = 1; i <= n; i++) dp.push_back(i);
8 | // for(int i = 0; i <= n; i++) cout< "hot" -> "dot" -> "dog" -> "cog",
22 | 返回它的长度 5。
23 | 示例 2:
24 |
25 | 输入:
26 | beginWord = "hit"
27 | endWord = "cog"
28 | wordList = ["hot","dot","dog","lot","log"]
29 |
30 | 输出: 0
31 |
32 | 解释: endWord "cog" 不在字典中,所以无法进行转换。
33 |
--------------------------------------------------------------------------------
/2019.01.06-leetcode695/岛屿的最大面积:
--------------------------------------------------------------------------------
1 | 给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合。你可以假设二维矩阵的四个边缘都被水包围着。
2 |
3 | 找到给定的二维数组中最大的岛屿面积。(如果没有岛屿,则返回面积为0。)
4 |
5 | 示例 1:
6 |
7 | [[0,0,1,0,0,0,0,1,0,0,0,0,0],
8 | [0,0,0,0,0,0,0,1,1,1,0,0,0],
9 | [0,1,1,0,1,0,0,0,0,0,0,0,0],
10 | [0,1,0,0,1,1,0,0,1,0,1,0,0],
11 | [0,1,0,0,1,1,0,0,1,1,1,0,0],
12 | [0,0,0,0,0,0,0,0,0,0,1,0,0],
13 | [0,0,0,0,0,0,0,1,1,1,0,0,0],
14 | [0,0,0,0,0,0,0,1,1,0,0,0,0]]
15 | 对于上面这个给定矩阵应返回 6。注意答案不应该是11,因为岛屿只能包含水平或垂直的四个方向的‘1’。
16 |
17 | 示例 2:
18 |
19 | [[0,0,0,0,0,0,0,0]]
20 | 对于上面这个给定的矩阵, 返回 0。
21 |
22 | 注意: 给定的矩阵grid 的长度和宽度都不超过 50。
23 |
--------------------------------------------------------------------------------
/2019.01.07-leetcode200/岛屿的个数:
--------------------------------------------------------------------------------
1 | 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量。一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的。你可以假设网格的四个边均被水包围。
2 |
3 | 示例 1:
4 |
5 | 输入:
6 | 11110
7 | 11010
8 | 11000
9 | 00000
10 |
11 | 输出: 1
12 | 示例 2:
13 |
14 | 输入:
15 | 11000
16 | 11000
17 | 00100
18 | 00011
19 |
20 | 输出: 3
21 |
--------------------------------------------------------------------------------
/2019.01.08-leetcode547/朋友圈:
--------------------------------------------------------------------------------
1 | 班上有 N 名学生。其中有些人是朋友,有些则不是。他们的友谊具有是传递性。如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友。所谓的朋友圈,是指所有朋友的集合。
2 |
3 | 给定一个 N * N 的矩阵 M,表示班级中学生之间的朋友关系。如果M[i][j] = 1,表示已知第 i 个和 j 个学生互为朋友关系,否则为不知道。你必须输出所有学生中的已知的朋友圈总数。
4 |
5 | 示例 1:
6 |
7 | 输入:
8 | [[1,1,0],
9 | [1,1,0],
10 | [0,0,1]]
11 | 输出: 2
12 | 说明:已知学生0和学生1互为朋友,他们在一个朋友圈。
13 | 第2个学生自己在一个朋友圈。所以返回2。
14 | 示例 2:
15 |
16 | 输入:
17 | [[1,1,0],
18 | [1,1,1],
19 | [0,1,1]]
20 | 输出: 1
21 | 说明:已知学生0和学生1互为朋友,学生1和学生2互为朋友,所以学生0和学生2也是朋友,所以他们三个在一个朋友圈,返回1。
22 | 注意:
23 |
24 | N 在[1,200]的范围内。
25 | 对于所有学生,有M[i][i] = 1。
26 | 如果有M[i][j] = 1,则有M[j][i] = 1。
27 |
--------------------------------------------------------------------------------
/2019.01.08-leetcode547/棕榈树.md:
--------------------------------------------------------------------------------
1 | ```
2 | public static int findCircleNum(int[][] M) {
3 | int count = 0;
4 | int[] visited = new int[M.length];
5 | for(int i=0;i2->5", "1->3"]
16 |
17 | 解释: 所有根节点到叶子节点的路径为: 1->2->5, 1->3
18 |
--------------------------------------------------------------------------------
/2019.01.15-leetcode46/全排列:
--------------------------------------------------------------------------------
1 | 给定一个没有重复数字的序列,返回其所有可能的全排列。
2 |
3 | 示例:
4 |
5 | 输入: [1,2,3]
6 | 输出:
7 | [
8 | [1,2,3],
9 | [1,3,2],
10 | [2,1,3],
11 | [2,3,1],
12 | [3,1,2],
13 | [3,2,1]
14 | ]
15 |
--------------------------------------------------------------------------------
/2019.01.16-leetcode47/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | vector> permuteUnique(vector& nums) {
5 | vector> res;
6 | sort(nums.begin(),nums.end());
7 | do
8 | {
9 | res.push_back(nums);
10 | }while(next_permutation(nums.begin(),nums.end()));
11 | return res;
12 | }
13 | };
14 | ```
15 |
--------------------------------------------------------------------------------
/2019.01.16-leetcode47/全排列II:
--------------------------------------------------------------------------------
1 | 给定一个可包含重复数字的序列,返回所有不重复的全排列。
2 |
3 | 示例:
4 |
5 | 输入: [1,1,2]
6 | 输出:
7 | [
8 | [1,1,2],
9 | [1,2,1],
10 | [2,1,1]
11 | ]
12 |
--------------------------------------------------------------------------------
/2019.01.17-leetcode77/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | vector> combine(int n, int k) {
5 | vector> res;
6 | vector out;
7 | helper(n, k, 1, out, res);
8 | return res;
9 | }
10 | void helper(int n, int k, int level, vector& out, vector>& res) {
11 | if (out.size() == k) res.push_back(out);
12 | for (int i = level; i <= n; ++i) {
13 | out.push_back(i);
14 | helper(n, k, i + 1, out, res);
15 | out.pop_back();
16 | }
17 | }
18 | };
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.01.17-leetcode77/组合:
--------------------------------------------------------------------------------
1 | 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。
2 |
3 | 示例:
4 |
5 | 输入: n = 4, k = 2
6 | 输出:
7 | [
8 | [2,4],
9 | [3,4],
10 | [2,3],
11 | [1,2],
12 | [1,3],
13 | [1,4],
14 | ]
15 |
--------------------------------------------------------------------------------
/2019.01.18-leetcode39/组合总和:
--------------------------------------------------------------------------------
1 | 给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。
2 |
3 | candidates 中的数字可以无限制重复被选取。
4 |
5 | 说明:
6 |
7 | 所有数字(包括 target)都是正整数。
8 | 解集不能包含重复的组合。
9 | 示例 1:
10 |
11 | 输入: candidates = [2,3,6,7], target = 7,
12 | 所求解集为:
13 | [
14 | [7],
15 | [2,2,3]
16 | ]
17 | 示例 2:
18 |
19 | 输入: candidates = [2,3,5], target = 8,
20 | 所求解集为:
21 | [
22 | [2,2,2,2],
23 | [2,3,3],
24 | [3,5]
25 | ]
26 |
--------------------------------------------------------------------------------
/2019.01.19-leetcode40/组合总和II:
--------------------------------------------------------------------------------
1 | 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。
2 |
3 | candidates 中的每个数字在每个组合中只能使用一次。
4 |
5 | 说明:
6 |
7 | 所有数字(包括目标数)都是正整数。
8 | 解集不能包含重复的组合。
9 | 示例 1:
10 |
11 | 输入: candidates = [10,1,2,7,6,1,5], target = 8,
12 | 所求解集为:
13 | [
14 | [1, 7],
15 | [1, 2, 5],
16 | [2, 6],
17 | [1, 1, 6]
18 | ]
19 | 示例 2:
20 |
21 | 输入: candidates = [2,5,2,1,2], target = 5,
22 | 所求解集为:
23 | [
24 | [1,2,2],
25 | [5]
26 | ]
27 |
--------------------------------------------------------------------------------
/2019.01.20-leetcode216/组合总和III:
--------------------------------------------------------------------------------
1 | 找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。
2 |
3 | 说明:
4 |
5 | 所有数字都是正整数。
6 | 解集不能包含重复的组合。
7 | 示例 1:
8 |
9 | 输入: k = 3, n = 7
10 | 输出: [[1,2,4]]
11 | 示例 2:
12 |
13 | 输入: k = 3, n = 9
14 | 输出: [[1,2,6], [1,3,5], [2,3,4]]
15 |
--------------------------------------------------------------------------------
/2019.01.21-leetcode78/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public List> subsets(int[] nums) {
4 | List> res = new ArrayList<>();
5 | dfs(0, nums, res, new ArrayList<>());
6 | return res;
7 | }
8 |
9 | private void dfs(int s, int[] nums, List> res, List list) {
10 | res.add(new ArrayList<>(list));
11 | for (int i = s; i < nums.length; ++i) {
12 | list.add(nums[i]);
13 | dfs(i + 1, nums, res, list);
14 | list.remove(list.size() - 1);
15 | }
16 | }
17 | }
18 | ```
19 |
--------------------------------------------------------------------------------
/2019.01.21-leetcode78/marguerite.md:
--------------------------------------------------------------------------------
1 | ```
2 |
3 | public class Solution {
4 | public List> subsets(int[] nums) {
5 | List> res = new ArrayList>();
6 | res.add(new ArrayList());
7 | for (int num : nums) { // ①从数组中取出每个元素
8 | int size = res.size();
9 | for (int i = 0; i < size; i++) {
10 | List temp = new ArrayList<>(res.get(i)); // ②逐一取出中间结果集
11 | temp.add(num); // ③将 num 放入中间结果集
12 | res.add(temp); // ④加入到结果集中
13 | }
14 | }
15 | return res;
16 | }
17 |
18 |
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.01.21-leetcode78/子集:
--------------------------------------------------------------------------------
1 | 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。
2 |
3 | 说明:解集不能包含重复的子集。
4 |
5 | 示例:
6 |
7 | 输入: nums = [1,2,3]
8 | 输出:
9 | [
10 | [3],
11 | [1],
12 | [2],
13 | [1,2,3],
14 | [1,3],
15 | [2,3],
16 | [1,2],
17 | []
18 | ]
19 |
--------------------------------------------------------------------------------
/2019.01.22-leetcode90/子集II:
--------------------------------------------------------------------------------
1 | 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。
2 |
3 | 说明:解集不能包含重复的子集。
4 |
5 | 示例:
6 |
7 | 输入: [1,2,2]
8 | 输出:
9 | [
10 | [2],
11 | [1],
12 | [1,2,2],
13 | [2,2],
14 | [1,2],
15 | []
16 | ]
17 |
--------------------------------------------------------------------------------
/2019.01.23-leetcode131/分割回文串:
--------------------------------------------------------------------------------
1 | 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。
2 |
3 | 返回 s 所有可能的分割方案。
4 |
5 | 示例:
6 |
7 | 输入: "aab"
8 | 输出:
9 | [
10 | ["aa","b"],
11 | ["a","a","b"]
12 | ]
13 |
--------------------------------------------------------------------------------
/2019.01.24-leetcode37/解数独:
--------------------------------------------------------------------------------
1 | 编写一个程序,通过已填充的空格来解决数独问题。
2 |
3 | 一个数独的解法需遵循如下规则:
4 |
5 | 数字 1-9 在每一行只能出现一次。
6 | 数字 1-9 在每一列只能出现一次。
7 | 数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。
8 | 空白格用 '.' 表示。
9 |
10 |
11 |
12 | 一个数独。
13 |
14 |
15 |
16 | 答案被标成红色。
17 |
18 | Note:
19 |
20 | 给定的数独序列只包含数字 1-9 和字符 '.' 。
21 | 你可以假设给定的数独只有唯一解。
22 | 给定数独永远是 9x9 形式的。
23 |
--------------------------------------------------------------------------------
/2019.01.25-leetcode51/N皇后:
--------------------------------------------------------------------------------
1 | n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。
2 |
3 |
4 |
5 | 上图为 8 皇后问题的一种解法。
6 |
7 | 给定一个整数 n,返回所有不同的 n 皇后问题的解决方案。
8 |
9 | 每一种解法包含一个明确的 n 皇后问题的棋子放置方案,该方案中 'Q' 和 '.' 分别代表了皇后和空位。
10 |
11 | 示例:
12 |
13 | 输入: 4
14 | 输出: [
15 | [".Q..", // 解法 1
16 | "...Q",
17 | "Q...",
18 | "..Q."],
19 |
20 | ["..Q.", // 解法 2
21 | "Q...",
22 | "...Q",
23 | ".Q.."]
24 | ]
25 | 解释: 4 皇后问题存在两个不同的解法。
26 |
--------------------------------------------------------------------------------
/2019.01.26-leetcode70/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int climbStairs(int n) {
5 | vector dp(n+3);
6 | dp[0]=0;
7 | dp[1]=1;
8 | dp[2]=2;
9 | for(int i = 3; i <= n; i++)
10 | {
11 | dp[i]=dp[i-1]+dp[i-2];
12 | }
13 | return dp[n];
14 | }
15 | };
16 | ```
17 |
--------------------------------------------------------------------------------
/2019.01.26-leetcode70/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int climbStairs(int n) {
4 | if (n <= 2) {
5 | return n;
6 | }
7 | int a = 1, b = 2;
8 | int res = 0;
9 | for (int i = 3; i <= n; ++i) {
10 | res = a + b;
11 | a = b;
12 | b = res;
13 | }
14 | return res;
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2019.01.26-leetcode70/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 70
2 | class Solution {
3 | public int climbStairs(int n) {
4 | if (n == 1) {
5 | return 1;
6 | }
7 | if (n == 2) {
8 | return 2;
9 | }
10 | int one=1;
11 | int two=2;
12 | int res=0;
13 | for (int i = 3; i <=n ; i++) {
14 | res=one+two;
15 | one=two;
16 | two=res;
17 | }
18 | return res;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/2019.01.26-leetcode70/棕榈树.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 |
4 | Map dp = new HashMap<>();
5 |
6 | public int climbStairs(int n) {
7 | if(n<0)
8 | return 0;
9 | if(n==0)
10 | return 1;
11 | if(dp.containsKey(n))
12 | return dp.get(n);
13 | int steps = climbStairs(n-1)+climbStairs(n-2);
14 | dp.put(n, steps);
15 | return steps;
16 | }
17 |
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.01.26-leetcode70/爬楼梯:
--------------------------------------------------------------------------------
1 | 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
2 |
3 | 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
4 |
5 | 注意:给定 n 是一个正整数。
6 |
7 | 示例 1:
8 |
9 | 输入: 2
10 | 输出: 2
11 | 解释: 有两种方法可以爬到楼顶。
12 | 1. 1 阶 + 1 阶
13 | 2. 2 阶
14 | 示例 2:
15 |
16 | 输入: 3
17 | 输出: 3
18 | 解释: 有三种方法可以爬到楼顶。
19 | 1. 1 阶 + 1 阶 + 1 阶
20 | 2. 1 阶 + 2 阶
21 | 3. 2 阶 + 1 阶
22 |
--------------------------------------------------------------------------------
/2019.01.27-leetcode198/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | //dp[i]:=走到第i家,获得的最大收入
3 | class Solution {
4 | public:
5 | int rob(vector& a) {
6 | int n = a.size();
7 | if(n==0) return 0;
8 | int dp[n+2];
9 | dp[0]=a[0];
10 | if(n==1) return a[0];
11 | dp[1]=max(a[0],a[1]);
12 | for(int i = 2; i < n; i++)
13 | {
14 | dp[i]=max(dp[i-2]+a[i],dp[i-1]);
15 | }
16 | return dp[n-1];
17 | }
18 | };
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.01.27-leetcode198/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int rob(int[] nums) {
4 | int pre2 = 0;
5 | int pre1 = 0;
6 | int cur = 0;
7 | for (int num : nums) {
8 | cur = Math.max(pre2 + num, pre1);
9 | pre2 = pre1;
10 | pre1 = cur;
11 | }
12 | return cur;
13 | }
14 | }
15 | ```
16 |
--------------------------------------------------------------------------------
/2019.01.27-leetcode198/sourcema.md:
--------------------------------------------------------------------------------
1 | # leetcode 198
2 | class Solution {
3 | public int rob(int[] nums) {
4 | if(nums==null||nums.length==0){
5 | return 0;
6 | }
7 | if(nums.length==1){
8 | return nums[0];
9 | }
10 | int[] dp=new int[nums.length];
11 | dp[0]=nums[0];
12 | dp[1]=Math.max(dp[0],nums[1]);
13 | for(int i=2;inums[1]?nums[0]:nums[1];
10 | }
11 | int[] dp = new int[nums.length];
12 | dp[0] = nums[0];
13 | dp[1] = nums[0]>nums[1]?nums[0]:nums[1];
14 | for(int i=2;i>& grid) {
5 | int n = grid.size();
6 | int m = grid[0].size();
7 | int dp[n+1][m+1];
8 | dp[0][0]=grid[0][0];
9 | for(int i = 1; i < n; i++) dp[i][0]=grid[i][0]+dp[i-1][0];
10 | for(int i = 1; i < m; i++) dp[0][i]=grid[0][i]+dp[0][i-1];
11 | for(int i = 1; i < n; i++){
12 | for(int j = 1; j < m; j++){
13 | dp[i][j] = min(dp[i-1][j]+grid[i][j],dp[i][j-1]+grid[i][j]);
14 | }
15 | }
16 | return dp[n-1][m-1];
17 | }
18 | };
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.01.29-leetcode64/最小路径和:
--------------------------------------------------------------------------------
1 | 给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。
2 |
3 | 说明:每次只能向下或者向右移动一步。
4 |
5 | 示例:
6 |
7 | 输入:
8 | [
9 | [1,3,1],
10 | [1,5,1],
11 | [4,2,1]
12 | ]
13 | 输出: 7
14 | 解释: 因为路径 1→3→1→1→1 的总和最小。
15 |
--------------------------------------------------------------------------------
/2019.01.30-leetcode62/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | #define ll long long
3 | class Solution {
4 | public:
5 | ll C(ll n, ll m)
6 | {
7 | if(m==0) return 1;
8 | return C(n,m-1)*(n-m+1)/m;
9 | }
10 | int uniquePaths(int m, int n) {
11 | int t = min(n,m);
12 | return C(n+m-2,t-1);
13 | }
14 | };
15 | ```
16 |
--------------------------------------------------------------------------------
/2019.01.30-leetcode62/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int uniquePaths(int m, int n) {
4 | int[] dp = new int[n];
5 | Arrays.fill(dp, 1);
6 | for (int i = 1; i < m; ++i) {
7 | for (int j = 1; j < n; ++j) {
8 | dp[j] += dp[j - 1];
9 | }
10 | }
11 | return dp[n - 1];
12 | }
13 | }
14 | ```
15 |
--------------------------------------------------------------------------------
/2019.01.30-leetcode62/sourcema.md:
--------------------------------------------------------------------------------
1 | # LeetCode 62
2 | class Solution {
3 | public int uniquePaths(int m, int n) {
4 | if (m == 1 || n == 1) {
5 | return 1;
6 | }
7 | int[][] dp = new int[m][n];
8 | for (int i = 1; i < n; i++) {
9 | dp[0][i]=1;
10 | }
11 | for (int i = 1; i < m; i++) {
12 | dp[i][0]=1;
13 | }
14 | for (int i = 1; i < m; i++) {
15 | for (int j = 1; j < n; j++) {
16 | dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
17 | }
18 | }
19 | return dp[m - 1][n - 1];
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/2019.01.30-leetcode62/不同路径:
--------------------------------------------------------------------------------
1 | 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。
2 |
3 | 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。
4 |
5 | 问总共有多少条不同的路径?
6 |
7 |
8 |
9 | 例如,上图是一个7 x 3 的网格。有多少可能的路径?
10 |
11 | 说明:m 和 n 的值均不超过 100。
12 |
13 | 示例 1:
14 |
15 | 输入: m = 3, n = 2
16 | 输出: 3
17 | 解释:
18 | 从左上角开始,总共有 3 条路径可以到达右下角。
19 | 1. 向右 -> 向右 -> 向下
20 | 2. 向右 -> 向下 -> 向右
21 | 3. 向下 -> 向右 -> 向右
22 | 示例 2:
23 |
24 | 输入: m = 7, n = 3
25 | 输出: 28
26 |
--------------------------------------------------------------------------------
/2019.01.30-leetcode62/棕榈树.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int uniquePaths(int m, int n) {
4 | int[][] map = new int[m][n];
5 | for(int i=0;i sum;
5 | NumArray(vector nums) {
6 | sum.push_back(0);
7 | for(int i = 0; i < nums.size(); i++)
8 | sum.push_back(nums[i]+sum.back());
9 | }
10 |
11 | int sumRange(int i, int j) {
12 | return sum[j+1]-sum[i];
13 | }
14 | };
15 |
16 | /**
17 | * Your NumArray object will be instantiated and called as such:
18 | * NumArray obj = new NumArray(nums);
19 | * int param_1 = obj.sumRange(i,j);
20 | */
21 | ```
22 |
--------------------------------------------------------------------------------
/2019.01.31-leetcode303/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class NumArray {
3 | private int[] sums;
4 |
5 | public NumArray(int[] nums) {
6 | sums = new int[nums.length + 1];
7 | for (int i = 0; i < nums.length; ++i) {
8 | sums[i + 1] = sums[i] + nums[i];
9 | }
10 | }
11 |
12 | public int sumRange(int i, int j) {
13 | return sums[j + 1] - sums[i];
14 | }
15 | }
16 |
17 | /**
18 | * Your NumArray object will be instantiated and called as such:
19 | * NumArray obj = new NumArray(nums);
20 | * int param_1 = obj.sumRange(i,j);
21 | */
22 | ```
23 |
--------------------------------------------------------------------------------
/2019.01.31-leetcode303/区域和检索-数组不可变:
--------------------------------------------------------------------------------
1 | 给定一个整数数组 nums,求出数组从索引 i 到 j (i ≤ j) 范围内元素的总和,包含 i, j 两点。
2 |
3 | 示例:
4 |
5 | 给定 nums = [-2, 0, 3, -5, 2, -1],求和函数为 sumRange()
6 |
7 | sumRange(0, 2) -> 1
8 | sumRange(2, 5) -> -1
9 | sumRange(0, 5) -> -3
10 | 说明:
11 |
12 | 你可以假设数组不可变。
13 | 会多次调用 sumRange 方法。
14 |
--------------------------------------------------------------------------------
/2019.02.01-leetcode413/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int numberOfArithmeticSlices(vector& A) {
5 | if(A.size()<3) return 0;
6 | int now = 0;
7 | int ans = 0;
8 | for(int i = 2; i < A.size(); i++){
9 | if(A[i]-A[i-1] == A[i-1]-A[i-2]) now++;
10 | else now = 0;
11 | ans+=now;
12 | }
13 |
14 | return ans;
15 | }
16 | };
17 | ```
18 |
--------------------------------------------------------------------------------
/2019.02.01-leetcode413/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int numberOfArithmeticSlices(int[] A) {
4 | if (A == null || A.length < 3) {
5 | return 0;
6 | }
7 | int res = 0;
8 | int cur = 0;
9 | for (int i = 2; i < A.length; ++i) {
10 | if (A[i] - A[i - 1] == A[i - 1] - A[i - 2]) {
11 | res += ++cur;
12 | } else {
13 | cur = 0;
14 | }
15 | }
16 | return res;
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.02.01-leetcode413/棕榈树.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int numberOfArithmeticSlices(int[] A) {
4 | int curr = 0;
5 | int sum = 0;
6 | for(int i=2;i> 1;
6 | for (int i = 1; i <= half; ++i) {
7 | for (int j = i; i + j <= n; ++j) {
8 | dp[i + j] = Math.max(dp[i + j], Math.max(i, dp[i]) * Math.max(j, dp[j]));
9 | }
10 | }
11 | return dp[n];
12 | }
13 | }
14 | ```
15 |
--------------------------------------------------------------------------------
/2019.02.02-leetcode343/整数拆分:
--------------------------------------------------------------------------------
1 | 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积。
2 |
3 | 示例 1:
4 |
5 | 输入: 2
6 | 输出: 1
7 | 解释: 2 = 1 + 1, 1 × 1 = 1。
8 | 示例 2:
9 |
10 | 输入: 10
11 | 输出: 36
12 | 解释: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36。
13 | 说明: 你可以假设 n 不小于 2 且不大于 58。
14 |
--------------------------------------------------------------------------------
/2019.02.03-leetocde279/Ostrichcrab.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public:
4 | int numSquares(int n) {
5 | vector dp;
6 | dp.push_back(0);
7 | for(int i = 1; i <= n; i++) dp.push_back(i);
8 | // for(int i = 0; i <= n; i++) cout<=0){
12 | min = Math.min(min, dp[i-j*j]+1);
13 | ++j;
14 | }
15 | dp[i] = min;
16 | }
17 | return dp[n];
18 | }
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/2019.02.09-leetcode91/解码方法:
--------------------------------------------------------------------------------
1 | 一条包含字母 A-Z 的消息通过以下方式进行了编码:
2 |
3 | 'A' -> 1
4 | 'B' -> 2
5 | ...
6 | 'Z' -> 26
7 | 给定一个只包含数字的非空字符串,请计算解码方法的总数。
8 |
9 | 示例 1:
10 |
11 | 输入: "12"
12 | 输出: 2
13 | 解释: 它可以解码为 "AB"(1 2)或者 "L"(12)。
14 | 示例 2:
15 |
16 | 输入: "226"
17 | 输出: 3
18 | 解释: 它可以解码为 "BZ" (2 26), "VF" (22 6), 或者 "BBF" (2 2 6) 。
19 |
--------------------------------------------------------------------------------
/2019.02.10-leetcode300/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int lengthOfLIS(int[] nums) {
4 | int[] dp = new int[nums.length];
5 | int len = 0;
6 | for (int num : nums) {
7 | int i = Arrays.binarySearch(dp, 0, len, num);
8 | if (i < 0) {
9 | i = -(i + 1);
10 | }
11 | dp[i] = num;
12 | if (i == len) {
13 | ++len;
14 | }
15 | }
16 | return len;
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.02.10-leetcode300/最长上升子序列:
--------------------------------------------------------------------------------
1 | 给定一个无序的整数数组,找到其中最长上升子序列的长度。
2 |
3 | 示例:
4 |
5 | 输入: [10,9,2,5,3,7,101,18]
6 | 输出: 4
7 | 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。
8 | 说明:
9 |
10 | 可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。
11 | 你算法的时间复杂度应该为 O(n2) 。
12 | 进阶: 你能将算法的时间复杂度降低到 O(n log n) 吗?
13 |
--------------------------------------------------------------------------------
/2019.02.11-leetcode646/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int findLongestChain(int[][] pairs) {
4 | if (pairs == null || pairs.length == 0) {
5 | return 0;
6 | }
7 | Arrays.sort(pairs, Comparator.comparingInt(o -> o[1]));
8 | int res = 1;
9 | int pre = pairs[0][1];
10 | for (int[] pair : pairs) {
11 | if (pair[0] > pre) {
12 | ++res;
13 | pre = pair[1];
14 | }
15 | }
16 | return res;
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.02.11-leetcode646/jackykun2012.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int findLongestChain(int[][] pairs) {
4 | if (pairs == null || pairs.length == 0) {
5 | return 0;
6 | }
7 | Arrays.sort(pairs, Comparator.comparingInt(o -> o[1]));
8 | int res = 1;
9 | int pre = pairs[0][1];
10 | for (int[] pair : pairs) {
11 | if (pair[0] > pre) {
12 | ++res;
13 | pre = pair[1];
14 | }
15 | }
16 | return res;
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.02.11-leetcode646/最长数对链:
--------------------------------------------------------------------------------
1 | 给出 n 个数对。 在每一个数对中,第一个数字总是比第二个数字小。
2 |
3 | 现在,我们定义一种跟随关系,当且仅当 b < c 时,数对(c, d) 才可以跟在 (a, b) 后面。我们用这种形式来构造一个数对链。
4 |
5 | 给定一个对数集合,找出能够形成的最长数对链的长度。你不需要用到所有的数对,你可以以任何顺序选择其中的一些数对来构造。
6 |
7 | 示例 :
8 |
9 | 输入: [[1,2], [2,3], [3,4]]
10 | 输出: 2
11 | 解释: 最长的数对链是 [1,2] -> [3,4]
12 | 注意:
13 |
14 | 给出数对的个数在 [1, 1000] 范围内。
15 |
--------------------------------------------------------------------------------
/2019.02.12-leetcode376/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int wiggleMaxLength(int[] nums) {
4 | if (nums.length < 2) {
5 | return nums.length;
6 | }
7 | int up = 1;
8 | int down = 1;
9 | for (int i = 1; i < nums.length; ++i) {
10 | if (nums[i] > nums[i - 1]) {
11 | up = down + 1;
12 | } else if (nums[i] < nums[i - 1]) {
13 | down = up + 1;
14 | }
15 | }
16 | return Math.max(up, down);
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.02.12-leetcode376/摆动序列:
--------------------------------------------------------------------------------
1 | 如果连续数字之间的差严格地在正数和负数之间交替,则数字序列称为摆动序列。第一个差(如果存在的话)可能是正数或负数。少于两个元素的序列也是摆动序列。
2 |
3 | 例如, [1,7,4,9,2,5] 是一个摆动序列,因为差值 (6,-3,5,-7,3) 是正负交替出现的。相反, [1,4,7,2,5] 和 [1,7,4,5,5] 不是摆动序列,第一个序列是因为它的前两个差值都是正数,第二个序列是因为它的最后一个差值为零。
4 |
5 | 给定一个整数序列,返回作为摆动序列的最长子序列的长度。 通过从原始序列中删除一些(也可以不删除)元素来获得子序列,剩下的元素保持其原始顺序。
6 |
7 | 示例 1:
8 |
9 | 输入: [1,7,4,9,2,5]
10 | 输出: 6
11 | 解释: 整个序列均为摆动序列。
12 | 示例 2:
13 |
14 | 输入: [1,17,5,10,13,15,10,5,16,8]
15 | 输出: 7
16 | 解释: 这个序列包含几个长度为 7 摆动序列,其中一个可为[1,17,10,13,10,16,8]。
17 | 示例 3:
18 |
19 | 输入: [1,2,3,4,5,6,7,8,9]
20 | 输出: 2
21 | 进阶:
22 | 你能否用 O(n) 时间复杂度完成此题?
23 |
--------------------------------------------------------------------------------
/2019.02.13-leetcode416/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | public boolean canPartition(int[] nums) {
3 | int sum = 0;
4 | for (int num : nums) {
5 | sum += num;
6 | }
7 | if ((sum & 1) == 1) {
8 | return false;
9 | }
10 | sum /= 2;
11 | boolean[] dp = new boolean[sum + 1];
12 | dp[0] = true;
13 | for (int num : nums) {
14 | for (int i = sum; i >= num; --i) {
15 | dp[i] = dp[i] || dp[i - num];
16 | if (dp[sum]) {
17 | return true;
18 | }
19 | }
20 | }
21 | return false;
22 | }
23 | ```
24 |
--------------------------------------------------------------------------------
/2019.02.13-leetcode416/分割等和子集:
--------------------------------------------------------------------------------
1 | 给定一个只包含正整数的非空数组。是否可以将这个数组分割成两个子集,使得两个子集的元素和相等。
2 |
3 | 注意:
4 |
5 | 每个数组中的元素不会超过 100
6 | 数组的大小不会超过 200
7 | 示例 1:
8 |
9 | 输入: [1, 5, 11, 5]
10 |
11 | 输出: true
12 |
13 | 解释: 数组可以分割成 [1, 5, 5] 和 [11].
14 |
15 |
16 | 示例 2:
17 |
18 | 输入: [1, 2, 3, 5]
19 |
20 | 输出: false
21 |
22 | 解释: 数组不能分割成两个元素和相等的子集.
23 |
--------------------------------------------------------------------------------
/2019.02.14-leetcode494/目标和:
--------------------------------------------------------------------------------
1 | 给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S。现在你有两个符号 + 和 -。对于数组中的任意一个整数,你都可以从 + 或 -中选择一个符号添加在前面。
2 |
3 | 返回可以使最终数组和为目标数 S 的所有添加符号的方法数。
4 |
5 | 示例 1:
6 |
7 | 输入: nums: [1, 1, 1, 1, 1], S: 3
8 | 输出: 5
9 | 解释:
10 |
11 | -1+1+1+1+1 = 3
12 | +1-1+1+1+1 = 3
13 | +1+1-1+1+1 = 3
14 | +1+1+1-1+1 = 3
15 | +1+1+1+1-1 = 3
16 |
17 | 一共有5种方法让最终目标和为3。
18 | 注意:
19 |
20 | 数组的长度不会超过20,并且数组中的值全为正数。
21 | 初始的数组的和不会超过1000。
22 | 保证返回的最终结果为32位整数。
23 |
--------------------------------------------------------------------------------
/2019.02.15-leetcode139/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public boolean wordBreak(String s, List wordDict) {
4 | Set set = new HashSet<>(wordDict);
5 | int n = s.length();
6 | boolean[] dp = new boolean[n + 1];
7 | dp[0] = true;
8 | for (int i = 1; i <= n; ++i) {
9 | for (int j = i; j >= 0; --j) {
10 | if (dp[j] && set.contains(s.substring(j, i))) {
11 | dp[i] = true;
12 | }
13 | }
14 | }
15 | return dp[n];
16 | }
17 | }
18 | ```
19 |
--------------------------------------------------------------------------------
/2019.02.15-leetcode139/单词拆分:
--------------------------------------------------------------------------------
1 | 给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。
2 |
3 | 说明:
4 |
5 | 拆分时可以重复使用字典中的单词。
6 | 你可以假设字典中没有重复的单词。
7 | 示例 1:
8 |
9 | 输入: s = "leetcode", wordDict = ["leet", "code"]
10 | 输出: true
11 | 解释: 返回 true 因为 "leetcode" 可以被拆分成 "leet code"。
12 | 示例 2:
13 |
14 | 输入: s = "applepenapple", wordDict = ["apple", "pen"]
15 | 输出: true
16 | 解释: 返回 true 因为 "applepenapple" 可以被拆分成 "apple pen apple"。
17 | 注意你可以重复使用字典中的单词。
18 | 示例 3:
19 |
20 | 输入: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
21 | 输出: false
22 |
--------------------------------------------------------------------------------
/2019.02.16-leetcode474/一和零:
--------------------------------------------------------------------------------
1 | 在计算机界中,我们总是追求用有限的资源获取最大的收益。
2 |
3 | 现在,假设你分别支配着 m 个 0 和 n 个 1。另外,还有一个仅包含 0 和 1 字符串的数组。
4 |
5 | 你的任务是使用给定的 m 个 0 和 n 个 1 ,找到能拼出存在于数组中的字符串的最大数量。每个 0 和 1 至多被使用一次。
6 |
7 | 注意:
8 |
9 | 给定 0 和 1 的数量都不会超过 100。
10 | 给定字符串数组的长度不会超过 600。
11 | 示例 1:
12 |
13 | 输入: Array = {"10", "0001", "111001", "1", "0"}, m = 5, n = 3
14 | 输出: 4
15 |
16 | 解释: 总共 4 个字符串可以通过 5 个 0 和 3 个 1 拼出,即 "10","0001","1","0" 。
17 | 示例 2:
18 |
19 | 输入: Array = {"10", "0", "1"}, m = 1, n = 1
20 | 输出: 2
21 |
22 | 解释: 你可以拼出 "10",但之后就没有剩余数字了。更好的选择是拼出 "0" 和 "1" 。
23 |
--------------------------------------------------------------------------------
/2019.02.17-leetcode322/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int coinChange(int[] coins, int amount) {
4 | int[] dp = new int[amount + 1];
5 | Arrays.fill(dp, amount + 1);
6 | dp[0] = 0;
7 | for (int i = 1; i <= amount; ++i) {
8 | for (int coin : coins) {
9 | if (i >= coin) {
10 | dp[i] = Math.min(dp[i], dp[i - coin] + 1);
11 | }
12 | }
13 | }
14 | return dp[amount] != amount + 1 ? dp[amount] : -1;
15 | }
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/2019.02.17-leetcode322/零钱兑换:
--------------------------------------------------------------------------------
1 | 给定不同面额的硬币 coins 和一个总金额 amount。编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 -1。
2 |
3 | 示例 1:
4 |
5 | 输入: coins = [1, 2, 5], amount = 11
6 | 输出: 3
7 | 解释: 11 = 5 + 5 + 1
8 | 示例 2:
9 |
10 | 输入: coins = [2], amount = 3
11 | 输出: -1
12 | 说明:
13 | 你可以认为每种硬币的数量是无限的。
14 |
--------------------------------------------------------------------------------
/2019.02.18-leetcode377/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int combinationSum4(int[] nums, int target) {
4 | int[] dp = new int[target + 1];
5 | dp[0] = 1;
6 | for (int i = 1; i <= target; ++i) {
7 | for (int num : nums) {
8 | if (i >= num) {
9 | dp[i] += dp[i - num];
10 | }
11 | }
12 | }
13 | return dp[target];
14 | }
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2019.02.18-leetcode377/组合总和IV:
--------------------------------------------------------------------------------
1 | 给定一个由正整数组成且不存在重复数字的数组,找出和为给定目标正整数的组合的个数。
2 |
3 | 示例:
4 |
5 | nums = [1, 2, 3]
6 | target = 4
7 |
8 | 所有可能的组合为:
9 | (1, 1, 1, 1)
10 | (1, 1, 2)
11 | (1, 2, 1)
12 | (1, 3)
13 | (2, 1, 1)
14 | (2, 2)
15 | (3, 1)
16 |
17 | 请注意,顺序不同的序列被视作不同的组合。
18 |
19 | 因此输出为 7。
20 | 进阶:
21 | 如果给定的数组中含有负数会怎么样?
22 | 问题会产生什么变化?
23 | 我们需要在题目中添加什么限制来允许负数的出现?
24 |
--------------------------------------------------------------------------------
/2019.02.19-leetcode309/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxProfit(int[] prices) {
4 | if (prices == null || prices.length <= 1) {
5 | return 0;
6 | }
7 | int curSell = 0;
8 | int preSell = 0;
9 | int buy = -prices[0];
10 | for (int i = 1; i < prices.length; ++i) {
11 | int tmp = curSell;
12 | curSell = Math.max(curSell, buy + prices[i]);
13 | buy = Math.max(buy, preSell - prices[i]);
14 | preSell = tmp;
15 | }
16 | return curSell;
17 | }
18 | }
19 | ```
20 |
--------------------------------------------------------------------------------
/2019.02.19-leetcode309/最佳买卖股票时机含冷冻期:
--------------------------------------------------------------------------------
1 | 给定一个整数数组,其中第 i 个元素代表了第 i 天的股票价格 。
2 |
3 | 设计一个算法计算出最大利润。在满足以下约束条件下,你可以尽可能地完成更多的交易(多次买卖一支股票):
4 |
5 | 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
6 | 卖出股票后,你无法在第二天买入股票 (即冷冻期为 1 天)。
7 | 示例:
8 |
9 | 输入: [1,2,3,0,2]
10 | 输出: 3
11 | 解释: 对应的交易状态为: [买入, 卖出, 冷冻期, 买入, 卖出]
12 |
--------------------------------------------------------------------------------
/2019.02.20-leetcode714/TheRocket.md:
--------------------------------------------------------------------------------
1 | ```java
2 | class Solution {
3 | public int maxProfit(int[] prices, int fee) {
4 | if (prices == null || prices.length <= 1) {
5 | return 0;
6 | }
7 | int sell = 0;
8 | int buy = -prices[0];
9 | for (int i = 1; i < prices.length; ++i) {
10 | sell = Math.max(sell, buy + prices[i] - fee);
11 | buy = Math.max(buy, sell - prices[i]);
12 | }
13 | return sell;
14 | }
15 | }
16 | ```
17 |
--------------------------------------------------------------------------------
/2019.02.20-leetcode714/买卖股票的最佳时机含手续费:
--------------------------------------------------------------------------------
1 | 给定一个整数数组 prices,其中第 i 个元素代表了第 i 天的股票价格 ;非负整数 fee 代表了交易股票的手续费用。
2 |
3 | 你可以无限次地完成交易,但是你每次交易都需要付手续费。如果你已经购买了一个股票,在卖出它之前你就不能再继续购买股票了。
4 |
5 | 返回获得利润的最大值。
6 |
7 | 示例 1:
8 |
9 | 输入: prices = [1, 3, 2, 8, 4, 9], fee = 2
10 | 输出: 8
11 | 解释: 能够达到的最大利润:
12 | 在此处买入 prices[0] = 1
13 | 在此处卖出 prices[3] = 8
14 | 在此处买入 prices[4] = 4
15 | 在此处卖出 prices[5] = 9
16 | 总利润: ((8 - 1) - 2) + ((9 - 4) - 2) = 8.
17 | 注意:
18 |
19 | 0 < prices.length <= 50000.
20 | 0 < prices[i] < 50000.
21 | 0 <= fee < 50000.
22 |
--------------------------------------------------------------------------------
/2019.02.21-leetcode123/买卖股票的最佳时机III:
--------------------------------------------------------------------------------
1 | 给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格。
2 |
3 | 设计一个算法来计算你所能获取的最大利润。你最多可以完成 两笔 交易。
4 |
5 | 注意: 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
6 |
7 | 示例 1:
8 |
9 | 输入: [3,3,5,0,0,3,1,4]
10 | 输出: 6
11 | 解释: 在第 4 天(股票价格 = 0)的时候买入,在第 6 天(股票价格 = 3)的时候卖出,这笔交易所能获得利润 = 3-0 = 3 。
12 | 随后,在第 7 天(股票价格 = 1)的时候买入,在第 8 天 (股票价格 = 4)的时候卖出,这笔交易所能获得利润 = 4-1 = 3 。
13 | 示例 2:
14 |
15 | 输入: [1,2,3,4,5]
16 | 输出: 4
17 | 解释: 在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。
18 | 注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。
19 | 因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。
20 | 示例 3:
21 |
22 | 输入: [7,6,4,3,1]
23 | 输出: 0
24 | 解释: 在这个情况下, 没有交易完成, 所以最大利润为 0。
25 |
--------------------------------------------------------------------------------
/2019.02.22-leetcode188/买卖股票的最佳时机IV:
--------------------------------------------------------------------------------
1 | 给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格。
2 |
3 | 设计一个算法来计算你所能获取的最大利润。你最多可以完成 k 笔交易。
4 |
5 | 注意: 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
6 |
7 | 示例 1:
8 |
9 | 输入: [2,4,1], k = 2
10 | 输出: 2
11 | 解释: 在第 1 天 (股票价格 = 2) 的时候买入,在第 2 天 (股票价格 = 4) 的时候卖出,这笔交易所能获得利润 = 4-2 = 2 。
12 | 示例 2:
13 |
14 | 输入: [3,2,6,5,0,3], k = 2
15 | 输出: 7
16 | 解释: 在第 2 天 (股票价格 = 2) 的时候买入,在第 3 天 (股票价格 = 6) 的时候卖出, 这笔交易所能获得利润 = 6-2 = 4 。
17 | 随后,在第 5 天 (股票价格 = 0) 的时候买入,在第 6 天 (股票价格 = 3) 的时候卖出, 这笔交易所能获得利润 = 3-0 = 3 。
18 |
--------------------------------------------------------------------------------
/2019.02.23-leetcode583/两个字符串的删除操作:
--------------------------------------------------------------------------------
1 | 给定两个单词 word1 和 word2,找到使得 word1 和 word2 相同所需的最小步数,每步可以删除任意一个字符串中的一个字符。
2 |
3 | 示例 1:
4 |
5 | 输入: "sea", "eat"
6 | 输出: 2
7 | 解释: 第一步将"sea"变为"ea",第二步将"eat"变为"ea"
8 | 说明:
9 |
10 | 给定单词的长度不超过500。
11 | 给定单词中的字符只含有小写字母。
12 |
--------------------------------------------------------------------------------
/2019.02.24-leetcode72/编辑距离:
--------------------------------------------------------------------------------
1 | 给定两个单词 word1 和 word2,计算出将 word1 转换成 word2 所使用的最少操作数 。
2 |
3 | 你可以对一个单词进行如下三种操作:
4 |
5 | 插入一个字符
6 | 删除一个字符
7 | 替换一个字符
8 | 示例 1:
9 |
10 | 输入: word1 = "horse", word2 = "ros"
11 | 输出: 3
12 | 解释:
13 | horse -> rorse (将 'h' 替换为 'r')
14 | rorse -> rose (删除 'r')
15 | rose -> ros (删除 'e')
16 | 示例 2:
17 |
18 | 输入: word1 = "intention", word2 = "execution"
19 | 输出: 5
20 | 解释:
21 | intention -> inention (删除 't')
22 | inention -> enention (将 'i' 替换为 'e')
23 | enention -> exention (将 'n' 替换为 'x')
24 | exention -> exection (将 'n' 替换为 'c')
25 | exection -> execution (插入 'u')
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # leetcode
2 | 每天一道leetcode
3 | >今天是2018年11月23,公众号:程序员乔戈里 博主会在毕业前每天刷一道leetcode,目前已经建立了leetcode刷题打卡群,需要的加我微信sometimesnaive123,进群,一周至少提交一道
4 |
--------------------------------------------------------------------------------
/Sagittarius.md:
--------------------------------------------------------------------------------
1 | 、、、
2 | class Solution {
3 | public:
4 | bool isPalindrome(string s) {
5 | if (s.empty()) return true;
6 |
7 | int l = 0, r = s.size() - 1;
8 | while (l < r) {
9 | if (!isalnum(s[l])) {
10 | l++; continue;
11 | }
12 | if (!isalnum(s[r])) {
13 | r--; continue;
14 | }
15 | if ((s[l] & 0xDF) != (s[r] & 0xDF)) return false; //通过位与运算 使小写字母转变为大写 而位或运算(|0x20)可将大写变为小写
16 | l++; r--;
17 | }
18 | return true;
19 | }
20 | };
21 | 、、、
22 |
--------------------------------------------------------------------------------
/Selfcenter.md:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public boolean isPalindrome(String s) {
3 |
4 | String t = s.replaceAll("[^A-Za-z0-9]", "");
5 | t = t.toLowerCase();
6 | int start =0;
7 | int end=t.length()-1;
8 | while(start<=end){
9 | if(t.charAt(start)!=t.charAt(end)) {
10 | return false;
11 | }
12 | start++;
13 | end--;
14 |
15 | }
16 |
17 | return true;
18 |
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/leetcode203/家.md:
--------------------------------------------------------------------------------
1 | ```
2 | func removeElements(head *ListNode, val int) *ListNode {
3 | prev := &ListNode{0,head}
4 | c := prev
5 | for head != nil{
6 | if head.Val == val {
7 | prev.Next = head.Next
8 | }else{
9 | prev = head
10 | }
11 | head = head.Next
12 | }
13 | return c.Next
14 | }
15 |
16 | ```
17 |
--------------------------------------------------------------------------------
/notKnow/句子.md:
--------------------------------------------------------------------------------
1 | ```
2 | class Solution {
3 | public int removeElement(int[] nums, int val) {
4 | int j=0;
5 | for(int i=0;i=0&&ch[i]==' ';i--);
9 | int j=i;
10 | for(;j>=0&&ch[j]!=' ';j--);
11 | return i-j;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------