public class Solution {
public int strStr(String haystack, String needle) {
int big = haystack.length();
int sub = needle.length();
if(big==0 && sub==0) return 0;
if(big==0 && sub!=0) return -1;
int index = big-sub;
for(int i=0;i<=index;i++){
if(haystack.substring(i,sub+i).equals(needle))return i;
}
return -1;
}
}

是int index = haystack.indexOf(needle)的另一种做法

Climbing Stairs

1)递归调用(容易内存溢出):

 public class Solution {
public int climbStairs(int n) {
if(n<1)return 0;
if(n==1)return 1;
if(n==2)return 2;
return climbStairs(n-1)+climbStairs(n-2);
}
}

2)类似斐波那契数列,开头1,2.代替1.1

 public class Solution {
public int climbStairs(int n) {
if(n<1)return 0;
if(n==1)return 1;
if(n==2)return 2;
int nums = 0;
int one = 1;
int two = 2;
for(int i=3;i<=n;i++){
nums = one+two;
one = two;
two = nums;
}
return nums;
}
}

https://leetcode.com/problems/climbing-stairs/#/description

刷题之Implement strStr()、Climbing Stairs的更多相关文章

  1. LeetCode专题-Python实现之第28题: Implement strStr()

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  2. leetCode练题——28. Implement strStr()

    1.题目 28. Implement strStr()——Easy Implement strStr(). Return the index of the first occurrence of ne ...

  3. Leetcode OJ 刷题

    Valid Palindrome吐槽一下Leetcode上各种不定义标准的输入输出(只是面试时起码能够问一下输入输出格式...),此篇文章不是详细的题解,是自己刷LeetCode的一个笔记吧,尽管没有 ...

  4. 【leetcode刷题笔记】Implement strStr()

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

  5. 刷题70. Climbing Stairs

    一.题目说明 题目70. Climbing Stairs,爬台阶(楼梯),一次可以爬1.2个台阶,n层的台阶有几种爬法.难度是Easy! 二.我的解答 类似的题目做过,问题就变得非常简单.首先用递归方 ...

  6. C#LeetCode刷题之#28-实现strStr()(Implement strStr())

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3895 访问. 实现 strStr() 函数. 给定一个 hays ...

  7. leetcode第27题--Implement strStr()

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

  8. leecode刷题(17)-- 实现StrStr

    leecode刷题(17)-- 实现StrStr 实现StrStr 描述: 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串 ...

  9. LeetCode练题——70. Climbing Stairs

    1.题目 70. Climbing Stairs——Easy You are climbing a stair case. It takes n steps to reach to the top. ...

随机推荐

  1. Java核心API需要掌握的程度

    分类: java技术2009-08-29 01:03 213人阅读 评论(0) 收藏 举报 javaapiswingxmlio Java的核心API是非常庞大的,这给开发者来说带来了很大的方便,经常人 ...

  2. 码云上部署hexo博客框架

    title: 码云上部署hexo博客框架 Hexo框架在码云上实现个人博客 本文受 https://www.jianshu.com/p/84ae2ba1c133 启发编写 本地调试 安装完Node.j ...

  3. python-模块加密hashlib

    import hashlib# md5ybm_pwd='yuanbapqingsdfs234FF234HF@F' #m = hashlib.md5() #bytes_ybq = ybm_pwd.enc ...

  4. LoadRunner之Block

    如何在一个脚本中实现不同事务不同次数的循环呢? 案例:假如你想在一个脚本中,实现登录执行1次,查询执行2次,插入执行3次,怎么办?录3个脚本?每个事务分别在脚本中复制N次? 当然不用,LR早就想到了你 ...

  5. 今日份学习:写一些代码 (Spring+AOP+Redis+MySQL练习)

    笔记 Spring+AOP+Redis+MySQL练习 1. 启动docker->mysql docker run --name mysql -v e:\docker:/var/lib/mysq ...

  6. spingboot2.0外部引入xml配置文件时找不到文件等报错

    之前的项目可以启动,后面不知道为什么都不行了,报错如下: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found bindin ...

  7. idea 将部分class文件打包成jar使用

    工作中有时候有太多模块堆放一块比较混乱,将某个功能(例如:三方支付)所需要的模块打包成jar使用起来会方便点. 步骤如下: 选择 Empty,然后为自己打的jar起个名字 然后在myjar上面右键 创 ...

  8. NoSql相关

    1  NoSQL, No Problem: An Intro to NoSQL Databases https://www.thoughtworks.com/insights/blog/nosql-n ...

  9. Hadoop数据压缩技术

    一.Hadoop数据压缩及其优缺点 1.压缩技术的好处与坏处 好处: 减少存储磁盘空间 降低IO(网络的IO和磁盘的IO) 加快数据在磁盘和网络中的传输速度,从而提高系统的处理速度. 坏处: 由于使用 ...

  10. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-eject

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...