Skip to content

feat: add swift solutions to lc problem: No. 0137 #892

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

Merged
merged 2 commits into from
Feb 17, 2023

Conversation

Qiu-IT
Copy link
Member

@Qiu-IT Qiu-IT commented Feb 17, 2023

愿这次是作规范了 没有打搅到您。

@YangFong
Copy link
Member

我尝试运行了一下,发现未通过,结果是标题取错了,这是 137 题

@Qiu-IT
Copy link
Member Author

Qiu-IT commented Feb 17, 2023

是 137题 思路和136一样 做题晕了 竟然给你添了这个麻烦

@Qiu-IT
Copy link
Member Author

Qiu-IT commented Feb 17, 2023

请问需要重新在PR的 还是等候您审查就可以了 这样的麽

@yanglbme
Copy link
Member

不需要重新提 pr,直接 push 改动到这个分支就行

@Qiu-IT Qiu-IT changed the title add swift solution to lc problem No. 0136 add swift solution to lc problem No. 0137 Feb 17, 2023
@Qiu-IT
Copy link
Member Author

Qiu-IT commented Feb 17, 2023

已经push 两份改动了REAMME 到分支上面了 谢谢您 (吐舌)

@Qiu-IT
Copy link
Member Author

Qiu-IT commented Feb 17, 2023

我尝试运行了一下,发现未通过,结果是标题取错了,这是 137 题

原来是另外大大吖 方才都木有留意哩
实在处理得有点犯晕 给您们加添了不少工作量

@yanglbme yanglbme merged commit 006523f into doocs:main Feb 17, 2023
@YangFong
Copy link
Member

这个解法可以再优化一下,遍历不要包含最后一个元素在内,可以省去一个判断:

class Solution {
  func singleNumber(_ nums: [Int]) -> Int {
    var a = nums.sorted()
    var n = a.count
    for i in stride(from: 0, through: n - 2, by: 3) {
      if a[i] != a[i + 1] {
        return a[i]
      }
    }
    return a[n - 1]
  }
}

同理,136 也是如此:

class Solution {
  func singleNumber(_ nums: [Int]) -> Int {
    var a = nums.sorted()
    var n = a.count
    for i in stride(from: 0, through: n - 2, by: 2) {
      if a[i] != a[i + 1] {
        return a[i]
      }
    }
    return a[n - 1]
  }
}

@Qiu-IT Qiu-IT deleted the solution0137 branch February 18, 2023 18:19
@Qiu-IT Qiu-IT changed the title add swift solution to lc problem No. 0137 feat: add swift solutions to lc problem No. 0137 Feb 21, 2023
@Qiu-IT Qiu-IT changed the title feat: add swift solutions to lc problem No. 0137 feat: add swift solutions to lc problem: No. 0137 Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants