-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat: add swift code to lcci problems: No.01.02,02.05 #2557
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
Conversation
klever34
commented
Apr 8, 2024
- I noticed there weren't any implementations in Swift, so I decided to add some.
- If this is approved, I'll go ahead with writing for the other implementations.
Signed-off-by: Lanre Adedara <adedaralanre@gmail.com>
🤭 感谢你的提交,请检查你的改动是否符合以下项目规范。 1. 格式化我们项目中各种编程语言代码(包括文档)所采用的格式化工具不同,提交 pr 之前必须确保代码、文档正确格式化。
2. Git 提交信息我们项目遵循 AngularJS Git Commit Message Conventions 规范,我们希望你的提交信息尽可能与项目保持一致。
3. 其它补充新增题解及代码时,需要创建 Solution.xxx 源代码文件(如果已存在,请确认算法是否更优,是则覆盖已有算法代码),同时,需要在 README.md 以及 README_EN.md 中添加对应的代码片段(英文文件中不要出现中文注释) 🤭 Thank you for your contribution. Please check if your changes comply with the following project specifications. 1. FormattingWe use different formatting tools for various programming languages (including documentation) in our project. You must ensure that the code and documentation are correctly formatted before submitting a pr.
2. Git Commit MessageOur project follows the AngularJS Git Commit Message Conventions. We hope that your submission information is as consistent as possible with the project.
3. Other notesWhen adding solutions and code, you need to create a Solution.xxx source code file (if it already exists, please confirm whether the algorithm is better, if yes, overwrite the existing algorithm code), and at the same time, you need to add the corresponding code snippets in README.md and README_EN.md (do not have Chinese comments in the English file) |
Hi @klever34 thanks for your contribution :) For the first question, the Swift code template is as follows: class Solution {
func isUnique(_ astr: String) -> Bool {
}
} And for the second question, the Swift code template is: class Solution {
func CheckPermutation(_ s1: String, _ s2: String) -> Bool {
}
} You need to complete the code based on the code provided here, and then paste the complete code into the corresponding Solution.swift file for each question. Additionally, there are two points to note:
Let me know if you need any further assistance! |
Signed-off-by: Lanre Adedara <adedaralanre@gmail.co>
Hi @yanglbme |
According to our project's guidelines, the code in Solution.swift should be identical to the Swift code snippet in the README. Therefore, please update the code for 02.05 as follows: /**
* Definition for singly-linked list.
* public class ListNode {
* public var val: Int
* public var next: ListNode?
* public init(_ val: Int) {
* self.val = val
* self.next = nil
* }
* }
*/
class Solution {
func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {
var carry = 0
let dummy = ListNode(0)
var current: ListNode? = dummy
var l1 = l1, l2 = l2
while l1 != nil || l2 != nil || carry != 0 {
let sum = (l1?.val ?? 0) + (l2?.val ?? 0) + carry
carry = sum / 10
current?.next = ListNode(sum % 10)
current = current?.next
l1 = l1?.next
l2 = l2?.next
}
return dummy.next
}
} Additionally, you need to place the Swift code for problem 01.02 into Solution 1 of README.md and README_EN.md, rather than Solution 2. It's preferable to use the same variable name |
Signed-off-by: Lanre Adedara <adedaralanre@gmail.com>
…4/leetcode into add-swift-implementation Signed-off-by: Lanre Adedara <adedaralanre@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks 👍