Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the code in array.swift #960

Merged
merged 2 commits into from
Nov 23, 2023
Merged

Simplify the code in array.swift #960

merged 2 commits into from
Nov 23, 2023

Conversation

KorsChen
Copy link
Contributor

文章中的插入删除操作,完全没必要用sequence。无论是性能,还是直观简便性上。对读者不友好建议换掉

@krahets krahets changed the title 简单点 Simplify the code in array.swift Nov 20, 2023
@nuomi1
Copy link
Contributor

nuomi1 commented Nov 23, 2023

original

数组 arr = [0, 0, 0, 0, 0]
数组 nums = [1, 3, 2, 5, 4]
在 nums 中获取随机元素 5
将数组长度扩展至 8 ,得到 nums = [1, 3, 2, 5, 4, 0, 0, 0]
在索引 3 处插入数字 6 ,得到 nums = [1, 3, 2, 6, 5, 4, 0, 0]
删除索引 2 处的元素,得到 nums = [1, 3, 6, 5, 4, 0, 0, 0]
在 nums 中查找元素 3 ,得到索引 = 1
yours

数组 arr = [0, 0, 0, 0, 0]
数组 nums = [1, 3, 2, 5, 4]
在 nums 中获取随机元素 3
将数组长度扩展至 8 ,得到 nums = [1, 3, 2, 5, 4, 0, 0, 0]
在索引 3 处插入数字 6 ,得到 nums = [1, 1, 1, 6, 1, 1, 1, 1]
删除索引 2 处的元素,得到 nums = [1, 1, 6, 1, 1, 1, 1, 1]
在 nums 中查找元素 3 ,得到索引 = -1
modified

数组 arr = [0, 0, 0, 0, 0]
数组 nums = [1, 3, 2, 5, 4]
在 nums 中获取随机元素 1
将数组长度扩展至 8 ,得到 nums = [1, 3, 2, 5, 4, 0, 0, 0]
在索引 3 处插入数字 6 ,得到 nums = [1, 3, 2, 6, 5, 4, 0, 0]
删除索引 2 处的元素,得到 nums = [1, 3, 6, 5, 4, 0, 0, 0]
在 nums 中查找元素 3 ,得到索引 = 1

Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@krahets krahets added code Code-related polish Decorative detail or feature labels Nov 23, 2023
@krahets krahets merged commit c5e37c1 into krahets:main Nov 23, 2023
7 checks passed
@KorsChen
Copy link
Contributor Author

Screenshot 2023-11-23 at 15 26 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Code-related polish Decorative detail or feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants