This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func isSubsequence(_ s: String, _ t: String) -> Bool { | |
| if s.count == t.count { return s == t } | |
| if s.count > t.count { return false } | |
| if s.count == 0 { return true } | |
| let tArray = Array(t) | |
| let sArray = Array(s) | |
| var sIndex = 0 | |
| var tIndex = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func isSubsequence(_ s: String, _ t: String) -> Bool { | |
| if s.count == t.count { return s == t } | |
| if s.count > t.count { return false } | |
| if s.count == 0 { return true } | |
| var tArray = Array(t) | |
| var sArray = Array(s) | |
| var sIndex = 0 | |
| var tIndex = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // MyView.swift | |
| // TestXib | |
| // | |
| // Created by Nigel on 2018/7/8. | |
| // Copyright © 2018年 Nigel. All rights reserved. | |
| // | |
| import UIKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func canConstruct(_ ransomNote: String, _ magazine: String) -> Bool { | |
| if ransomNote.count == magazine.count { return ransomNote == magazine } | |
| if ransomNote.count > magazine.count { return false } | |
| if ransomNote.count == 0 { return true } | |
| var mapping = [Character: Int]() | |
| for char in ransomNote { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func canConstruct(_ ransomNote: String, _ magazine: String) -> Bool { | |
| if ransomNote.count == magazine.count { return ransomNote == magazine } | |
| if ransomNote.count > magazine.count { return false } | |
| if ransomNote.count == 0 { return true } | |
| var mapping = [Character: Int]() | |
| for char in ransomNote { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func singleNumber(_ nums: [Int]) -> Int { | |
| return nums.reduce(0, ^) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func singleNumber(_ nums: [Int]) -> Int { | |
| var mapping = [Int: Bool]() | |
| for num in nums { | |
| if let _ = mapping[num] { | |
| mapping[num] = true | |
| }else { | |
| mapping.updateValue(false, forKey: num) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func sumOfLeftLeaves(_ root: TreeNode?) -> Int { | |
| return dfs(root: root, isLeft: false) | |
| } | |
| func dfs(root: TreeNode?, isLeft: Bool) -> Int { | |
| guard let root = root else { return 0 } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func sumOfLeftLeaves(_ root: TreeNode?) -> Int { | |
| return dfs(root: root, isLeft: false) | |
| } | |
| func dfs(root: TreeNode?, isLeft: Bool) -> Int { | |
| guard let root = root else { return 0 } | |
| var result = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func countSegments(_ s: String) -> Int { | |
| return Array(s).split(separator: " ").count | |
| } | |
| } |