Comments (10)
len 包含了 len2的信息
from cs-notes.
你的len是取得最小值,怎么会包含len2,测试用例 aa bb 1, 1000 你看你输出的是什么
from cs-notes.
最小长度就是 len2 和 s2.length() 的最小值,这是没错的。
from cs-notes.
这个笔记没加在 README 中,还没整理完,忘记在仓库中删除了,没想到会有人看…现在不建议看
from cs-notes.
哈哈,知道了,不过你的这个代码还是有误啊,测试用例aa bb 1 100,输出竟然是27,怎么可能呢。。应该是很大很大的
from cs-notes.
我现在在坐车,回去的时候再看一下。这个题目本身就比较坑,没有描述清楚,我也是参考别人的代码才搞懂…
from cs-notes.
好的,没事,我参考你的思路改了一点
public static int getCount(String str1, String str2, int len1, int len2){
int[] subtractArr = new int[len2];
char c1, c2;
for(int i = 0; i < len2; i++){
c1 = i < str1.length() ? str1.charAt(i) : 'a' - 1;
c2 = i < str2.length() ? str2.charAt(i) : 'a' - 1;
subtractArr[i] = c2 - c1;
}
int ans = 0;
for(int i = len1; i <= len2; i++){
for(int j = 0; j < i; j++){
ans = (ans + ((int)(subtractArr[j] * Math.pow(26, i - j - 1))) % MOD) % MOD;
}
}
return ans - 1;
}
from cs-notes.
@specialYY 你提供的测试用例,aa bb 1 1000 输出结果为 27 是正确的。虽然你指定了 len2 的长度为 1000,但是字符串最大长度为 2,因此超过 2 的部分就不需要考虑了。
题目没有明确说明长度超过字符串的长度时应该怎么处理,怎么解释都可以,我的代码也是可以通过的。我想,牛客网的在线编程系统应该只有 len2 <= str2.length() 的测试用例,所以两种解法都可以通过。
from cs-notes.
也是题目没说清若len2大于字符串长度怎么处理。刚看了一下,又更新了很多资料,都是干货啊。这得花多少时间整理啊!
from cs-notes.
@specialYY 从去年十一月份开始准备到现在
from cs-notes.
Related Issues (20)
- no se vale
- 题解-排序Kth Largest Element in an Array翻译有误 HOT 2
- 基础知识
- 我也在打造这方面的知识库:www.yuque.com/it-coach 能一起合作吗
- Kaschey758
- Suggestion HOT 1
- Kaschey758
- 89840200099962655961 HOT 1
- 0888999999*89840200011162655961# HOT 2
- 学习
- leetcode最新pdf还有吗 HOT 10
- 0888999999#89840200011162655961
- 计算机网络 - 应用层.md -- 2. ARP 解析 MAC 地址
- 计算机操作系统 - 进程管理 进程调度算法部分,“先来先服务 first-come first-serverd”,serverd拼写错误
- 关于微服务的开发相关知识整理有没有 HOT 8
- 剑指Offer的 [树][二叉搜索树的第K的结点] 链接被newcoder修改 HOT 9
- java
- N
- 在线阅读网址打不开了 HOT 7
- 标题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cs-notes.