Can be divided by 3?
来源:互联网 发布:淘宝中信v卡有什么好处 编辑:程序博客网 时间:2024/05/18 02:51
实现一个function,输入是一个string,string里的每一个字符都是‘0-9’,所以它每个substring都可以表示一个整数。输出其最长的可以被三整除的substring的长度。例如“1012300‘
用range sum的idea,从左边开始往右边扫,一边扫一遍累加,把第一个出现mod3余1和mod3余2的和的下标存起来。然后当后面再出现余1或者余2的和的时候,就可以减去之前存的坐标及这个坐标之前的数。就可以得到一个相加和为3的倍数的范围。然后再找出最长的一个就可以了。时间是线性的。
链接: https://instant.1point3acres.com/thread/176873
来源: 一亩三分地
I really love this idea. for example 1111122222->1201210210 -> 120121021(longest),2012102,01210210 -> 111112222
This is really smart and takes liner time.
0 0
- Can be divided by 3?
- For men, can be divided into three forms of MONCLER jacket can be divided into three types
- 三分频, Clock Frequency divided by 3
- Accessible apps can be used by everyone,
- Accessible apps can be used by everyone
- 二分频, Clock Frequency divided by two
- what energy function can be minimized by graph cuts
- Solaris11 :Roles can only be assumed by authorized users
- The packages can be overrided by Java Endorsed Standards
- regular polygon can be drawn only by straightedge and compass
- Workplan Structure Locked By One User, Can be Unlocked By Another
- A Docking control that can be dragged and resized by the user
- This tag and its children can be replaced by one <TextView/> and a compound drawable
- This tag and its children can be replaced by one <TextView/> and a compound drawable
- Exercises2.1 E4(how many permutations can be obtained by using stack)
- This tag and its children can be replaced by one <TextView/> and a compound drawable
- This tag and its children can be replaced by one <TextView/> and a compound drawable
- SP2-0678: Column or attribute type can not be displayed by SQL*Plus
- Android onTouchEvent,onClick,onLongClick的return值注意事项
- Html的空格显示
- Loadrunner常见的检查点函数
- MIT6.828课程学习初步
- 聊聊并发(十)生产者消费者模式
- Can be divided by 3?
- app触控的代码
- 上面俩题的小结-派生类访问基类私有成员的方法
- 成为软件工程师最精彩的地方是什么
- 12个非常实用的JavaScript小技巧
- 【数据结构】 栈和队列 YTU 2242: 回文(栈和队列)
- C++ 查找本机安装word的版本号,
- setPadding()无效的原因分析
- 关于quartz cron表达式饭解析验证输出实现部分截图代码