内容简介:如果当前没有针对性的话,那就从头把之前补上。
2 0 1 9 -5 -14 星 期二 开 始 吧
如果当前没有针对性的话,那就从头把之前补上。
上 一 题 链 接 Leetcode基础刷题之 PHP 解析(2. Add Two Numbers)
题 目 描 述
给定一个字符串,让我们求最长无重复的字符子串,从例3中可以看出来,求的是连续最长的。如果不是连续结果就是pwke了。
题 目 分 析
这里遍历整个字符串,定义一个变量用来存储字符串,定义一个变量存储最大的长度,只要出现重复了,说明此时就是从头到当前字母无重复的最大长度,我们需要把开始计算位置移至它的下一个位置即可。每次保存最大连续长度,直至遍历结束。
/** * @param String $s * @return Integer */ function lengthOfLongestSubstring($s) { $max = 0; $current = ''; $len=$i=0; for (;$i < strlen($s); $i++) { if (strpos($current, $s[$i]) !== false) { $current = substr($current, strpos($current, $s[$i])+1); $len = strlen($current); } $current .= $s[$i]; $len++; $max = max($max, $len); } return $max; }
Github整理地址: https://github.com/wuqinqiang/leetcode-php
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Apache Flink 零基础入门(一):基础概念解析
- Apache Flink 零基础入门(一):基础概念解析
- JStorm 源码解析:基础线程模型
- React Hooks 解析(上):基础
- TypeScript基础入门之模块解析(一)
- TypeScript基础入门之模块解析(二)
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Making Things See
Greg Borenstein / Make / 2012-2-3 / USD 39.99
Welcome to the Vision Revolution. With Microsoft's Kinect leading the way, you can now use 3D computer vision technology to build digital 3D models of people and objects that you can manipulate with g......一起来看看 《Making Things See》 这本书的介绍吧!