hello-algo/codes
KLYkl 9e914f8792
Update array_deque.cpp
将43行的return (i + capacity()) % capacity();改为return (i % capacity() + capacity()) % capacity();
原因:原来的表达式“(i + capacity()) % capacity();”如果i是负数的话,需要保证capacity() >= -i。而更改后的表达式“ (i % capacity() + capacity()) % capacity();” 中的先对i取模相加,最后再取模操作会确保结果是一个非负整数,并且不会超过 capacity() 的值。这是因为取模操作会返回一个在 0 到 capacity() - 1 范围内的数,即使原始的和可能是负数。保证函数index()的传入形参i<-capacity()不会崩溃,且能正确返回 0 到 capacity() - 1 范围内的的索引值。
2024-05-17 13:33:46 +08:00
..
c Bug fixes and improvements (#1348) 2024-05-06 14:44:48 +08:00
cpp Update array_deque.cpp 2024-05-17 13:33:46 +08:00
csharp feat: Add glossary and description for "哈希集合" (#1310) 2024-04-28 22:00:25 +08:00
dart feat: Add glossary and description for "哈希集合" (#1310) 2024-04-28 22:00:25 +08:00
go Maintain the same semantics as other languages in n_queens.go (#1329) 2024-05-03 19:40:59 +08:00
java feat: Add glossary and description for "哈希集合" (#1310) 2024-04-28 22:00:25 +08:00
javascript Bug fixes and improvements (#1348) 2024-05-06 14:44:48 +08:00
kotlin feat: Add glossary and description for "哈希集合" (#1310) 2024-04-28 22:00:25 +08:00
python Bug fixes and improvements (#1318) 2024-04-30 15:52:05 +08:00
pythontutor Several bug fixes and improvements (#1178) 2024-03-26 02:49:26 +08:00
ruby feat: add ruby code - chapter "divide and conquer" (#1361) 2024-05-15 18:14:15 +08:00
rust [Rust] Use arrays instead of vectors in Chapter 4.1 Array (#1357) 2024-05-15 18:31:48 +08:00
swift feat: Add glossary and description for "哈希集合" (#1310) 2024-04-28 22:00:25 +08:00
typescript Bug fixes and improvements (#1348) 2024-05-06 14:44:48 +08:00
zig Fix bugs and harmonize the code comments (#1199) 2024-03-31 03:06:41 +08:00
docker-compose.yml Several bug fixes and improvements (#945) 2023-11-14 21:27:35 +08:00
Dockerfile feat(csharp) .NET 8.0 code migration (#966) 2023-11-26 23:18:44 +08:00