├── Images
└── logo1.png
├── Package.swift
├── HRSwift.xcodeproj
├── project.xcworkspace
│ └── contents.xcworkspacedata
├── xcuserdata
│ └── yansongli.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
├── xcshareddata
│ └── xcschemes
│ │ ├── HRSwiftTests.xcscheme
│ │ └── HRSwift.xcscheme
└── project.pbxproj
├── HRSwift
├── GoogleInterviewQuestions.swift
├── TestFile
│ └── MaximiseSum
│ │ └── output10.txt
├── ViewController.swift
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.storyboard
├── Info.plist
└── AppDelegate.swift
├── Sources
├── Int+HRSwift.swift
├── Helper.swift
├── ThirtyDaysOfCodeChallenges.swift
├── Leetcode
│ ├── String
│ │ ├── 344_ReverseString.swift
│ │ ├── 205_IsomorphicString.swift
│ │ ├── 345_ReverseVowelsOfAString.swift
│ │ └── 290_WordPattern.swift
│ ├── Tree
│ │ ├── 98_ValidateBinarySearchTree.swift
│ │ ├── 112_PathSum.swift
│ │ ├── 226_InvertBinaryTree.swift
│ │ ├── 110_BalancedBinaryTree.swift
│ │ ├── 100_SameTree.swift
│ │ ├── 102_BinaryTreeLevelOrderTraversal.swift
│ │ ├── 113_PathSumII.swift
│ │ ├── 104_MaximumDepthOfBinaryTree.swift
│ │ ├── 111_MinimumDepthOfBinaryTree.swift
│ │ ├── 105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift
│ │ ├── 337_HouseRobberIII.swift
│ │ ├── 106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift
│ │ └── 101_SymmetricTree.swift
│ └── LeetCodeKit.swift
├── Implementation.swift
├── IndeedPrime.swift
├── Search.swift
├── Strings.swift
├── ZenefitsContest.swift
└── DynamicProgramming.swift
├── .travis.yml
├── .gitignore
├── HRSwiftTests
├── Info.plist
└── HRSwiftTests.swift
├── HRSwiftUITests
├── Info.plist
└── HRSwiftUITests.swift
├── LICENSE
└── README.md
/Images/logo1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jindulys/HackerRankSolutions/HEAD/Images/logo1.png
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | import PackageDescription
2 | let package = Package(
3 | name: "HRSwift"
4 | )
5 |
--------------------------------------------------------------------------------
/HRSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/HRSwift/GoogleInterviewQuestions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // File.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-02-05.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 |
12 | // Question1 Give you a binary tree, check whether left tree's value's sum is equal to right tree's value's sum.
--------------------------------------------------------------------------------
/Sources/Int+HRSwift.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Int+HRSwift.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-02-01.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | public extension Int {
12 | public static func random(range: Range) -> Int {
13 | return range.startIndex + Int(arc4random_uniform(UInt32(range.endIndex.predecessor()-range.startIndex)))
14 | }
15 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: objective-c
2 | osx_image: xcode7
3 | xcode_project: HRSwift.xcodeproj
4 | xcode_scheme: HRSwift
5 | SDK: iphonesimulator9.1
6 |
7 | before_install:
8 | - brew update
9 | - brew upgrade xctool
10 |
11 | script:
12 | - xctool -project HRSwift.xcodeproj -scheme HRSwift clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
13 | - xctool test -project HRSwift.xcodeproj -scheme HRSwiftTests -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
14 |
--------------------------------------------------------------------------------
/Sources/Helper.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Array+HRSwift.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-02-01.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 | let N = 600000
11 | let LargeInt = 1 << 12
12 |
13 |
14 | public class Helper {
15 | public static func LargeIntArray() -> [Int] {
16 | var retVal = Array(count: N, repeatedValue: 0)
17 | for i in 0..
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/HRSwiftUITests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Sources/Leetcode/String/344_ReverseString.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 344_ReverseString.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:344 Reverse String
13 | URL: https://leetcode.com/problems/reverse-string/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class ReverseString_Solution {
19 | func reverseString(s: String) -> String {
20 | var characters = Array(s.characters)
21 | guard characters.count > 0 else {
22 | return ""
23 | }
24 | var startIndex = 0
25 | var endIndex = characters.count - 1
26 | while startIndex < endIndex {
27 | let tmp = characters[startIndex]
28 | characters[startIndex] = characters[endIndex]
29 | characters[endIndex] = tmp
30 | startIndex += 1
31 | endIndex -= 1
32 | }
33 | return String(characters)
34 | }
35 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/98_ValidateBinarySearchTree.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 98_ValidateBinarySearchTree.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:98 Validate Binary Search Tree
13 | URL: https://leetcode.com/problems/validate-binary-search-tree/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | /// Inorder traversal.
19 | class ValidateBinaryTree_Solution {
20 | func isValidBST(root: TreeNode?) -> Bool {
21 | var inorderList: [Int] = []
22 | inorderTraversal(root, nodeList: &inorderList)
23 | return inorderList.isStrictlyIncreasing
24 | }
25 |
26 | func inorderTraversal(root: TreeNode?, inout nodeList: [Int]) {
27 | guard let root = root else {
28 | return
29 | }
30 | inorderTraversal(root.left, nodeList: &nodeList)
31 | nodeList.append(root.val)
32 | inorderTraversal(root.right, nodeList: &nodeList)
33 | }
34 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/112_PathSum.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 112_PathSum.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:112 Path Sum
13 | URL: https://leetcode.com/problems/path-sum/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class PathSum_Solution {
19 |
20 | var target: Int = Int.max
21 |
22 | func hasPathSum(root: TreeNode?, _ sum: Int) -> Bool {
23 | self.target = sum
24 | return dfsSum(root, prevSum: 0)
25 | }
26 |
27 | private func dfsSum(root: TreeNode?, prevSum: Int) -> Bool {
28 | guard let root = root else {
29 | return false
30 | }
31 |
32 | let currentSum = prevSum + root.val
33 |
34 | if (root.left == nil) && (root.right == nil) && currentSum == target {
35 | return true
36 | }
37 |
38 | return dfsSum(root.left, prevSum: currentSum) || dfsSum(root.right, prevSum: currentSum)
39 | }
40 | }
--------------------------------------------------------------------------------
/HRSwift.xcodeproj/xcuserdata/yansongli.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | HRSwift.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 | HRSwiftTests.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 1
16 |
17 |
18 | SuppressBuildableAutocreation
19 |
20 | 0E5741861C001FAF004EB0FA
21 |
22 | primary
23 |
24 |
25 | 0E57419A1C001FAF004EB0FA
26 |
27 | primary
28 |
29 |
30 | 0E5741A51C001FAF004EB0FA
31 |
32 | primary
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Sources/Leetcode/String/205_IsomorphicString.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 205_IsomorphicString.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-07.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:205 Isomorphic Strings
13 | URL: https://leetcode.com/problems/isomorphic-strings/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class IsomorphicString_Solution {
19 | func isIsomorphic(s: String, _ t: String) -> Bool {
20 | guard s.characters.count > 0 else {
21 | return true
22 | }
23 | var sTotMap: [Character : Character] = [:]
24 | var tTosMap: [Character : Character] = [:]
25 | let sCharacters = Array(s.characters)
26 | let tCharacters = Array(t.characters)
27 | for i in 0.. TreeNode? {
45 | guard let root = root else {
46 | return nil
47 | }
48 | invertTree(root.left)
49 | invertTree(root.right)
50 | let tmp = root.left
51 | root.left = root.right
52 | root.right = tmp
53 | return root
54 | }
55 | }
--------------------------------------------------------------------------------
/HRSwift/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2015-11-20.
6 | // Copyright © 2015 yansong li. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 | // Do any additional setup after loading the view, typically from a nib.
16 |
17 | let root = TreeNode(1)
18 |
19 | let rootleft = TreeNode(2)
20 | let rootright = TreeNode(2)
21 |
22 | let leftRight = TreeNode(3)
23 |
24 | let rightRight = TreeNode(3)
25 |
26 | root.left = rootleft
27 | root.right = rootright
28 | root.left?.right = leftRight
29 | root.right?.right = rightRight
30 |
31 | let pathSum = PathSumII_Solution()
32 | print(pathSum.pathSum(root, 6))
33 |
34 | let reverseVowels = ReverseVowels_Solution()
35 | print(reverseVowels.reverseVowels("a."))
36 | }
37 |
38 | override func didReceiveMemoryWarning() {
39 | super.didReceiveMemoryWarning()
40 | // Dispose of any resources that can be recreated.
41 | }
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/110_BalancedBinaryTree.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 110_BalancedBinaryTree.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-05.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:110 Balanced Binary Tree
13 | URL: https://leetcode.com/problems/balanced-binary-tree/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class BalancedBinaryTree_Solution {
19 | func isBalanced(root: TreeNode?) -> Bool {
20 | let(ans, _) = balancedAt(root)
21 | return ans
22 | }
23 |
24 | /// Detect whether a treenode is balanced, return the detection result and
25 | /// Depth of the treenode
26 | /// - parameter root: the root treenode.
27 | private func balancedAt(root: TreeNode?) -> (Bool, Int) {
28 | guard let root = root else {
29 | return (true, 0)
30 | }
31 | let (leftBalanced, leftDepth) = balancedAt(root.left)
32 | let (rightBalanced, rightDepth) = balancedAt(root.right)
33 | let subTreeBalanced = leftBalanced && rightBalanced
34 | let noMoreThanOne = abs(leftDepth - rightDepth) <= 1
35 | let depth = max(leftDepth, rightDepth)
36 | return (subTreeBalanced && noMoreThanOne, depth + 1)
37 | }
38 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/100_SameTree.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 100_SameTree.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-02.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Given two binary trees, write a function to check if they are equal or not.
13 |
14 | Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
15 | */
16 |
17 | /**
18 | Swift Knowledge:
19 |
20 | Enum Comparison
21 |
22 | Algorithem Knowledge:
23 |
24 | Recursive call.
25 | */
26 |
27 | /**
28 | 100. Same Tree
29 | https://leetcode.com/problems/same-tree/
30 | */
31 |
32 | class Solution_SameTree {
33 | func isSameTree(p: TreeNode?, _ q: TreeNode?) -> Bool {
34 | switch(p, q){
35 | case (let .Some(leftRoot), let .Some(rightRoot)):
36 | let valEqual = (leftRoot.val == rightRoot.val)
37 | let leftEqual = isSameTree(leftRoot.left, rightRoot.left)
38 | let rightEqual = isSameTree(leftRoot.right, rightRoot.right)
39 | return valEqual && leftEqual && rightEqual
40 | case (.None, .None):
41 | return true
42 | default:
43 | return false
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/String/345_ReverseVowelsOfAString.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 345_ReverseVowelsOfAString.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:345 Reverse Vowels of a String
13 | URL: https://leetcode.com/problems/reverse-vowels-of-a-string/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class ReverseVowels_Solution {
19 | func reverseVowels(s: String) -> String {
20 | let vowels:[Character] = ["a","A", "e","E", "i","I", "o","O", "u", "U"]
21 | var characters = Array(s.characters)
22 | var start = 0
23 | var end = characters.count - 1
24 | while start < end {
25 | for i in start...end {
26 | start = i
27 | if vowels.contains(characters[i]) {
28 | break
29 | }
30 | }
31 | if start == end {
32 | break
33 | }
34 | for i in SRange(start: end, end: start-1, step: -1) {
35 | end = i
36 | if vowels.contains(characters[i]) {
37 | break
38 | }
39 | }
40 | if start == end {
41 | break
42 | }
43 | let tmp = characters[start]
44 | characters[start] = characters[end]
45 | characters[end] = tmp
46 | start += 1
47 | end -= 1
48 | }
49 | return String(characters)
50 | }
51 | }
--------------------------------------------------------------------------------
/HRSwiftUITests/HRSwiftUITests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // HRSwiftUITests.swift
3 | // HRSwiftUITests
4 | //
5 | // Created by yansong li on 2015-11-20.
6 | // Copyright © 2015 yansong li. All rights reserved.
7 | //
8 |
9 | import XCTest
10 |
11 | class HRSwiftUITests: XCTestCase {
12 |
13 | override func setUp() {
14 | super.setUp()
15 |
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 |
18 | // In UI tests it is usually best to stop immediately when a failure occurs.
19 | continueAfterFailure = false
20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
21 | XCUIApplication().launch()
22 |
23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
24 | }
25 |
26 | override func tearDown() {
27 | // Put teardown code here. This method is called after the invocation of each test method in the class.
28 | super.tearDown()
29 | }
30 |
31 | func testExample() {
32 | // Use recording to get started writing UI tests.
33 | // Use XCTAssert and related functions to verify your tests produce the correct results.
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/HRSwift/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/102_BinaryTreeLevelOrderTraversal.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 102_BinaryTreeLevelOrderTraversal.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-04.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Swift Knowledge:
13 |
14 | Queue, Array
15 |
16 | Algorithem Knowledge:
17 |
18 | BFS
19 | */
20 |
21 | /**
22 | 102. Binary Tree Level Order Traversal
23 | https://leetcode.com/problems/binary-tree-level-order-traversal/
24 | */
25 |
26 | class BinaryTreeLevelOrderTraversal_Solution {
27 | func levelOrder(root: TreeNode?) -> [[Int]] {
28 | guard let root = root else {
29 | return []
30 | }
31 | var queue = Queue<(TreeNode, Int)>()
32 | var ans: [[Int]] = [[]]
33 | queue.enqueue((root, 1))
34 | while !queue.isEmpty() {
35 | let (currentNode, currentlevel) = queue.dequeue()!
36 | if ans.count == currentlevel {
37 | var lastLevelNodes = ans.removeLast()
38 | lastLevelNodes.append(currentNode.val)
39 | ans.append(lastLevelNodes)
40 | } else if ans.count < currentlevel {
41 | let newLevelNodes = [currentNode.val];
42 | ans.append(newLevelNodes)
43 | }
44 | if let left = currentNode.left {
45 | queue.enqueue((left, currentlevel + 1))
46 | }
47 | if let right = currentNode.right {
48 | queue.enqueue((right, currentlevel + 1))
49 | }
50 | }
51 | return ans
52 | }
53 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/113_PathSumII.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 113_PathSumII.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:113 Path Sum II
13 | URL: https://leetcode.com/problems/path-sum-ii/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | /**
19 | Swift Knowledge:
20 |
21 | Inout Parameter
22 |
23 | Algorithem Knowledge:
24 |
25 | Stack, DFS
26 | */
27 |
28 | class PathSumII_Solution {
29 | var satisfiedRouts: [[Int]] = []
30 | var target: Int = 0
31 | func pathSum(root: TreeNode?, _ sum: Int) -> [[Int]] {
32 | self.target = sum
33 | var routeStack:[Int] = []
34 | DFSSum(root, prevSum: 0, routeStack: &routeStack)
35 | return satisfiedRouts
36 | }
37 |
38 | private func DFSSum(root: TreeNode?, prevSum: Int, inout routeStack: [Int]) {
39 | guard let root = root else {
40 | return
41 | }
42 | let currentSum = root.val + prevSum
43 | routeStack.append(root.val)
44 | if root.left == nil && root.right == nil {
45 | if currentSum == self.target {
46 | self.satisfiedRouts.append(routeStack)
47 | }
48 | routeStack.removeLast()
49 | print(routeStack)
50 | return
51 | }
52 | DFSSum(root.left, prevSum: currentSum, routeStack: &routeStack)
53 | DFSSum(root.right, prevSum: currentSum, routeStack: &routeStack)
54 | // Note: remove here since we have finished this node's check.
55 | routeStack.removeLast()
56 | }
57 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/104_MaximumDepthOfBinaryTree.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 104_MaximumDepthOfBinaryTree.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-03.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Given a binary tree, find its maximum depth.
13 |
14 | The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
15 | */
16 |
17 | /**
18 | Swift Knowledge:
19 |
20 | Generic, custom struct, tuple, optional
21 |
22 | Algorithem Knowledge:
23 |
24 | 1) How to define meaningful helper object like nodeQueue maximumDepth means we need
25 | to treverse all elements according to the level.
26 | 2) Breadth first treverse.
27 | 3) Queue.
28 | */
29 |
30 | /**
31 | 104. Maximum Depth of Binary Tree
32 | https://leetcode.com/problems/maximum-depth-of-binary-tree/
33 | */
34 |
35 | class MaximumDepthOfBinaryTree_Solution {
36 | func maxDepth(root: TreeNode?) -> Int {
37 | guard let root = root else { return 0 }
38 | var nodeQueue = Queue<(TreeNode, Int)>()
39 | nodeQueue.enqueue((root, 1))
40 | var maxLevel = 1
41 | while !nodeQueue.isEmpty() {
42 | let (currentNode, currentLevel) = nodeQueue.dequeue()!
43 | maxLevel = currentLevel
44 | let currentLeft = currentNode.left
45 | let currentRight = currentNode.right
46 | if let left = currentLeft {
47 | nodeQueue.enqueue((left, currentLevel + 1))
48 | }
49 | if let right = currentRight {
50 | nodeQueue.enqueue((right, currentLevel + 1))
51 | }
52 | }
53 | return maxLevel
54 | }
55 | }
--------------------------------------------------------------------------------
/HRSwift/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/HRSwift/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/Sources/Leetcode/LeetCodeKit.swift:
--------------------------------------------------------------------------------
1 | //
2 | // LeetCodeKit.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-04.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | // MARK: TreeNode
12 |
13 | public class TreeNode {
14 | public var val: Int
15 | public var left: TreeNode?
16 | public var right: TreeNode?
17 | public init(_ val: Int) {
18 | self.val = val
19 | self.left = nil
20 | self.right = nil
21 | }
22 | }
23 |
24 | /// HashableTreeNode is a wrapper around TreeNode, to facilitate Hash.
25 | public class HashableTreeNode {
26 | public var val: Int
27 | public var left: HashableTreeNode?
28 | public var right: HashableTreeNode?
29 | public var id: Int
30 |
31 | public init(val: Int, id: Int) {
32 | self.val = val
33 | self.id = id
34 | }
35 |
36 | /// Helper function to build a HashableTreeNode with TreeNode.
37 | public class func buildHashableTreeWith(root: TreeNode?, id: Int = 0) -> HashableTreeNode? {
38 | guard let root = root else {
39 | return nil
40 | }
41 | let hashableRoot = HashableTreeNode(val: root.val, id: id)
42 | let leftHashableRoot = self.buildHashableTreeWith(root.left, id: id * 2 + 1)
43 | let rightHashableRoot = self.buildHashableTreeWith(root.right, id: id * 2 + 2)
44 | hashableRoot.left = leftHashableRoot
45 | hashableRoot.right = rightHashableRoot
46 | return hashableRoot
47 | }
48 | }
49 |
50 | extension HashableTreeNode: Hashable {
51 | public var hashValue: Int {
52 | return self.id
53 | }
54 | }
55 |
56 | public func ==(lhs: HashableTreeNode, rhs: HashableTreeNode) -> Bool {
57 | return lhs.hashValue == rhs.hashValue
58 | }
--------------------------------------------------------------------------------
/HRSwift/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/111_MinimumDepthOfBinaryTree.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 111_MinimumDepthOfBinaryTree.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-03.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Given a binary tree, find its minimum depth.
13 |
14 | The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
15 | */
16 |
17 | /**
18 | Swift Knowledge:
19 |
20 | Generic, custom struct, tuple, optional
21 |
22 | Algorithem Knowledge:
23 |
24 | 1) How to define meaningful helper object like nonLeafQueue means you will store
25 | node that is not a leaf.
26 | 2) Breadth first treverse.
27 | 3) Queue
28 | */
29 |
30 | /**
31 | 111. Minimum Depth of Binary Tree
32 | https://leetcode.com/problems/minimum-depth-of-binary-tree/
33 | */
34 |
35 | class MinimumDepthOfBinaryTree_Solution {
36 | func minDepth(root: TreeNode?) -> Int {
37 | if let root = root {
38 | var nonLeafQueue = Queue<(TreeNode, Int)>()
39 | nonLeafQueue.enqueue((root, 1))
40 | var (currentNode, currentLevel) = nonLeafQueue.dequeue()!
41 | while currentNode.left != nil || currentNode.right != nil {
42 | if let left = currentNode.left, right = currentNode.right {
43 | nonLeafQueue.enqueue((left, (currentLevel + 1)))
44 | nonLeafQueue.enqueue((right, (currentLevel + 1)))
45 | } else if let left = currentNode.left {
46 | nonLeafQueue.enqueue((left, (currentLevel + 1)))
47 | } else {
48 | nonLeafQueue.enqueue((currentNode.right!, (currentLevel + 1)))
49 | }
50 | (currentNode, currentLevel) = nonLeafQueue.dequeue()!
51 | }
52 | return currentLevel
53 | }
54 | return 0
55 | }
56 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/String/290_WordPattern.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 290_WordPattern.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:290 Word Pattern
13 | URL: https://leetcode.com/problems/word-pattern/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class WordPattern_Solution {
19 | /// This is correct but with ugly logic
20 | func wordPattern_initial(pattern: String, _ str: String) -> Bool {
21 | var dict: [Character : String] = [:]
22 | var wordIndexedDict: [String: Character] = [:]
23 | let keys:[Character] = Array(pattern.characters)
24 | let words = str.characters.split(" ").map { String($0) }
25 | guard words.count == keys.count else {
26 | return false
27 | }
28 | for i in 0.. Bool {
47 | var characterIndexedDict: [Character : String] = [:]
48 | var wordIndexedDict: [String: Character] = [:]
49 | let keys:[Character] = Array(pattern.characters)
50 | let words = str.characters.split(" ").map { String($0) }
51 | guard words.count == keys.count else {
52 | return false
53 | }
54 | for i in 0.. Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:105 Construct Binary Tree From Preorder and Ignorer Traversal
13 | URL: https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class TreeBuildPreorderInorder_Solution {
19 | func buildTree(preorder: [Int], _ inorder: [Int]) -> TreeNode? {
20 | guard preorder.count > 0 &&
21 | inorder.count > 0 &&
22 | preorder.count == inorder.count else {
23 | return nil
24 | }
25 | return treeBuildHelper(preorder,
26 | preStartIndex: 0,
27 | preEndIndex: preorder.count - 1,
28 | inorder: inorder,
29 | inorderStartIndex: 0,
30 | inorderEndIndex: inorder.count - 1)
31 | }
32 | func treeBuildHelper(preorder: [Int],
33 | preStartIndex: Int,
34 | preEndIndex: Int,
35 | inorder: [Int],
36 | inorderStartIndex: Int,
37 | inorderEndIndex: Int) -> TreeNode? {
38 | guard preStartIndex <= preEndIndex &&
39 | inorderStartIndex <= inorderEndIndex else {
40 | return nil
41 | }
42 | let rootVal = preorder[preStartIndex]
43 | let currentRoot = TreeNode(rootVal)
44 | var mid: Int = 0
45 | for i in inorderStartIndex...inorderEndIndex {
46 | if inorder[i] == rootVal {
47 | mid = i
48 | break
49 | }
50 | }
51 | currentRoot.left = treeBuildHelper(preorder,
52 | preStartIndex: preStartIndex + 1,
53 | preEndIndex: preStartIndex + mid - inorderStartIndex,
54 | inorder: inorder,
55 | inorderStartIndex: inorderStartIndex,
56 | inorderEndIndex: mid - 1)
57 | currentRoot.right = treeBuildHelper(preorder,
58 | preStartIndex: preStartIndex + mid - inorderStartIndex + 1,
59 | preEndIndex: preEndIndex,
60 | inorder: inorder,
61 | inorderStartIndex: mid + 1,
62 | inorderEndIndex: inorderEndIndex)
63 | return currentRoot
64 | }
65 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/337_HouseRobberIII.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 337_HouseRobberIII.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-04.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Swift Knowledge:
13 |
14 | Hashable, Equality, Memoization(awesome!), Functional Programming
15 |
16 | Algorithem Knowledge:
17 |
18 | DFS Traverse, DP Programming
19 | */
20 |
21 | /**
22 | public func memoize( body:((T)->U, T)->U ) -> (T)->U {
23 | var memo = Dictionary()
24 | var result: ((T)->U)!
25 | result = { x in
26 | if let q = memo[x] { return q }
27 | let r = body(result, x)
28 | memo[x] = r
29 | return r
30 | }
31 | return result
32 | }
33 | */
34 |
35 | /**
36 | 337. House Robber III
37 | https://leetcode.com/problems/house-robber-iii/
38 | */
39 |
40 | class HouseRobberIII_Solution {
41 | func rob(root: TreeNode?) -> Int {
42 | guard let root = root else {
43 | return 0
44 | }
45 | let hashableRoot = HashableTreeNode.buildHashableTreeWith(root)
46 | let ans: (HashableTreeNode) -> Int = memoize { (ans, currentNode) -> Int in
47 | var robRoot = currentNode.val
48 | var robNonRoot = 0
49 | if let left = currentNode.left {
50 | if let leftLeft = left.left {
51 | robRoot += ans(leftLeft)
52 | }
53 | if let leftRight = left.right {
54 | robRoot += ans(leftRight)
55 | }
56 | robNonRoot += ans(left)
57 | }
58 | if let right = currentNode.right {
59 | if let rightLeft = right.left {
60 | robRoot += ans(rightLeft)
61 | }
62 | if let rightRight = right.right {
63 | robRoot += ans(rightRight)
64 | }
65 | robNonRoot += ans(right)
66 | }
67 | return max(robRoot, robNonRoot)
68 | }
69 | return ans(hashableRoot!)
70 | }
71 |
72 | /// Second solution. A little better than first one.
73 | func robII(root: TreeNode?) -> Int {
74 | let ans = subRob(root)
75 | return max(ans[0], ans[1])
76 | }
77 |
78 | /// SubRob will calculate from the root and return an Array of 2.
79 | /// A[0]: The maximum money if root is Robbed.
80 | /// A[1]: The maximum money if root is not Robbed.
81 | private func subRob(root: TreeNode?) -> [Int] {
82 | guard let root = root else {
83 | return [0, 0]
84 | }
85 | let leftProfit = subRob(root.left)
86 | let rightProfit = subRob(root.right)
87 | // If root is rob then left, right must not be robbed.
88 | let robRootProfit = root.val + leftProfit[1] + rightProfit[1]
89 | let robNonRootProfit =
90 | max(leftProfit[0], leftProfit[1]) + max(rightProfit[0], rightProfit[1])
91 | return [robRootProfit, robNonRootProfit]
92 | }
93 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:106 Construct Binary Tree From Inorder and Postorder Traversal
13 | URL: https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class BuildTreeInorderPostOrder_Solution {
19 | func buildTree(inorder: [Int], _ postorder: [Int]) -> TreeNode? {
20 | guard inorder.count > 0 && postorder.count > 0 && inorder.count == postorder.count else {
21 | return nil
22 | }
23 | return treeBuildHelper(inorder,
24 | inorderStart: 0,
25 | inorderEnd: inorder.count - 1,
26 | postorder: postorder,
27 | postStart: 0,
28 | postEnd: postorder.count - 1)
29 | }
30 |
31 | private func treeBuildHelper(inorder: [Int],
32 | inorderStart: Int,
33 | inorderEnd: Int,
34 | postorder: [Int],
35 | postStart: Int,
36 | postEnd: Int) -> TreeNode? {
37 | guard inorderStart <= inorderEnd && postStart <= postEnd else {
38 | return nil
39 | }
40 | var mid: Int = 0
41 | let rootVal = postorder[postEnd]
42 | let rootNode = TreeNode(rootVal)
43 | for i in inorderStart...inorderEnd {
44 | if inorder[i] == rootVal {
45 | mid = i
46 | break
47 | }
48 | }
49 | // Note: when calculate postEnd we use the following formula:
50 | // X - postStart : is how many elements between those two index
51 | // mid - inorderStart = left tree element counts
52 | // X - postStart + 1(the first element) == mid - inorderStart
53 | rootNode.left = treeBuildHelper(inorder,
54 | inorderStart: inorderStart,
55 | inorderEnd: mid - 1,
56 | postorder: postorder,
57 | postStart: postStart,
58 | postEnd: postStart + mid - inorderStart - 1)
59 | rootNode.right = treeBuildHelper(inorder,
60 | inorderStart: mid + 1,
61 | inorderEnd: inorderEnd,
62 | postorder: postorder,
63 | postStart: postStart + mid - inorderStart,
64 | postEnd: postEnd - 1)
65 | return rootNode
66 | }
67 | }
--------------------------------------------------------------------------------
/Sources/Leetcode/Tree/101_SymmetricTree.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 101_SymmetricTree.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2016-08-06.
6 | // Copyright © 2016 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /**
12 | Title:101 Symmetric Tree
13 | URL: https://leetcode.com/problems/symmetric-tree/
14 | Space: O(n)
15 | Time: O(n)
16 | */
17 |
18 | class SymmetricTree_Solution {
19 | /// Bonus points: Iterative
20 | func isSymmetric(root: TreeNode?) -> Bool {
21 | guard let root = root else {
22 | return true
23 | }
24 | let original = self.treeToArray(root)
25 | let switchedRoot = self.switchSubTree(root)
26 | let switched = self.treeToArray(switchedRoot)
27 | let comparison = zip(original, switched).map {
28 | return $0 == $1
29 | }.reduce(true) {
30 | $0 && $1
31 | }
32 | return comparison
33 | }
34 |
35 | private func switchSubTree(root: TreeNode) -> TreeNode {
36 | var switchedLeft: TreeNode?
37 | var switchedRight: TreeNode?
38 | if let left = root.left {
39 | switchedLeft = switchSubTree(left)
40 | }
41 | if let right = root.right {
42 | switchedRight = switchSubTree(right)
43 | }
44 | root.left = switchedRight
45 | root.right = switchedLeft
46 | return root
47 | }
48 |
49 | /// Use a queue to convert a tree to an array.
50 | private func treeToArray(root: TreeNode?) -> [TreeValue] {
51 | guard let root = root else {
52 | return [TreeValue.Empty]
53 | }
54 | var traversalQueue = Queue()
55 | var retVal: [TreeValue] = [.Valid(root.val)]
56 | traversalQueue.enqueue(root)
57 | while !traversalQueue.isEmpty() {
58 | let currentNode = traversalQueue.dequeue()!
59 | if let left = currentNode.left {
60 | retVal.append(.Valid(left.val))
61 | traversalQueue.enqueue(left)
62 | } else {
63 | retVal.append(.Empty)
64 | }
65 | if let right = currentNode.right {
66 | retVal.append(.Valid(right.val))
67 | traversalQueue.enqueue(right)
68 | } else {
69 | retVal.append(.Empty)
70 | }
71 | }
72 | return retVal
73 | }
74 |
75 | /// A simpler solution, recursive
76 | func solutionTwo(root: TreeNode?) -> Bool {
77 | guard let root = root else {
78 | return true
79 | }
80 | return symmetricHelper(root.left, q: root.right)
81 | }
82 |
83 | private func symmetricHelper(p: TreeNode?, q: TreeNode?) -> Bool {
84 | if p == nil && q == nil {
85 | return true
86 | }
87 | if p == nil || q == nil || p?.val != q?.val {
88 | return false
89 | }
90 | return symmetricHelper(p?.left, q: q?.right) && symmetricHelper(p?.right, q: q?.left)
91 | }
92 | }
93 |
94 | enum TreeValue {
95 | case Valid(Int)
96 | case Empty
97 | }
98 |
99 | extension TreeValue: Equatable { }
100 |
101 | func ==(lhs: TreeValue, rhs: TreeValue) -> Bool {
102 | switch (lhs, rhs) {
103 | case (.Valid(let lval), .Valid(let rval)):
104 | return lval == rval
105 | case (.Empty, .Empty):
106 | return true
107 | default:
108 | return false
109 | }
110 | }
--------------------------------------------------------------------------------
/HRSwift.xcodeproj/xcshareddata/xcschemes/HRSwiftTests.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
14 |
15 |
17 |
23 |
24 |
25 |
26 |
27 |
33 |
34 |
35 |
36 |
37 |
38 |
48 |
50 |
56 |
57 |
58 |
59 |
60 |
61 |
67 |
68 |
74 |
75 |
76 |
77 |
79 |
80 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/Sources/Implementation.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WarmUp.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2015-11-24.
6 | // Copyright © 2015 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | // https://www.hackerrank.com/challenges/angry-professor
12 | public class AngryProfessor {
13 |
14 | public init() {}
15 |
16 | func solution() -> Void {
17 | let TN = Int(getLine())!
18 | for _ in 0..= K {
26 | print("YES")
27 | } else {
28 | print("NO")
29 | }
30 | }
31 | }
32 | }
33 |
34 | // https://www.hackerrank.com/challenges/sherlock-and-the-beast
35 | public class SherlockAndTheBeast {
36 |
37 | public init() {}
38 |
39 | func solution() -> Void {
40 | let TN = Int(getLine())!
41 | for _ in 0.. String {
48 | for i in SRange(start: cypher/3*3, end:-1, step:-3) {
49 | if (cypher - i) % 5 == 0 {
50 | let fives = String(count: i, repeatedValue: Character("5"))
51 | let threes = String(count: cypher-i, repeatedValue: Character("3"))
52 | return fives + threes
53 | }
54 | }
55 | return "-1"
56 | }
57 | }
58 |
59 | public class UtopianTree {
60 | var heights:[Int]
61 |
62 | static func generatesHeights() -> [Int] {
63 | var heights = [1]
64 | var h = 1
65 | for i in 0..<60 {
66 | // Normal remainder operator
67 | //if (i%2 == 0) {
68 | if (i & 1 == 0) {
69 | h = h*2
70 | } else {
71 | h = h+1
72 | }
73 | heights.append(h)
74 | }
75 | return heights
76 | }
77 |
78 | public init() {
79 | heights = UtopianTree.generatesHeights()
80 | }
81 |
82 | func solution() -> Void {
83 | let T = Int(getLine())!
84 | for _ in 0.. Void {
111 | let T = getInt()
112 | for _ in 0.. Int {
126 | if arr.count == 0 { return -1 }
127 | var low = 0
128 | var high = arr.count - 1
129 | while (low < high && arr[(low + high)/2] != target) {
130 | if arr[(low + high)/2] < target {
131 | low = (low + high)/2 + 1
132 | } else {
133 | high = (low + high)/2 - 1
134 | }
135 | }
136 | if arr[(low + high)/2] == target {
137 | return (low + high)/2
138 | }
139 | if arr[low] < target {
140 | return low
141 | } else {
142 | return low - 1
143 | }
144 | }
145 | }
146 |
147 |
148 |
--------------------------------------------------------------------------------
/HRSwift.xcodeproj/xcshareddata/xcschemes/HRSwift.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
43 |
49 |
50 |
51 |
52 |
53 |
59 |
60 |
61 |
62 |
63 |
64 |
74 |
76 |
82 |
83 |
84 |
85 |
86 |
87 |
93 |
95 |
101 |
102 |
103 |
104 |
106 |
107 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/Sources/IndeedPrime.swift:
--------------------------------------------------------------------------------
1 | //
2 | // IndeedPrime.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2015-12-12.
6 | // Copyright © 2015 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | public class TheUltimateQuestion {
12 | public init() {}
13 |
14 | func solution() {
15 | let inputs = getLineToArray().map {Int($0)!}
16 | let addSum = (inputs.reduce(0, combine: +), "\(inputs[0])+\(inputs[1])+\(inputs[2])")
17 | let multiSum = (inputs.reduce(1, combine: *),"\(inputs[0])*\(inputs[1])*\(inputs[2])")
18 | let addMulti = (inputs[0] + inputs[1] * inputs[2],"\(inputs[0])+\(inputs[1])*\(inputs[2])")
19 | let multiAdd = (inputs[0] * inputs[1] + inputs[2], "\(inputs[0])*\(inputs[1])+\(inputs[2])")
20 |
21 | let myResults = [addSum, multiSum, addMulti, multiAdd]
22 | let results = myResults.filter {$0.0 == 42}
23 | if results.count > 0 {
24 | print(results[0].1)
25 | } else {
26 | print("This is not the ultimate question")
27 | }
28 | }
29 | }
30 |
31 | public class RelatedSpecies {
32 | public init() {}
33 | func solution() {
34 | let T = Int(getLine())!
35 | for _ in 0.. currentMax {
49 | print("NO")
50 | return
51 | }
52 | let currentMin = min(a[i], b[i])
53 | if currentMin >= current {
54 | current = currentMin
55 | } else {
56 | current = currentMax
57 | }
58 | }
59 | print("YES")
60 | }
61 |
62 | // Divide and conquer
63 | }
64 |
65 | public class Gretchen {
66 |
67 | public init() {}
68 | // Overtime
69 | func solution() {
70 | var parameters = getLineToArray().map {Int($0)!}
71 | let M = parameters[0]
72 | let N = parameters[1]
73 | let Q = parameters[2]
74 |
75 | var actors = getLineToArray().map {Int($0)!}
76 | var scenesTree = [AVLTree]()
77 | for _ in 0..())
79 | }
80 | for i in 0..(Int, Int) {
28 | if M <= 1 {
29 | return (-1, -1)
30 | }
31 | var pair: [Int: Int] = [:]
32 | for (iIndex, i) in prices.enumerate() {
33 | if let pIndex = pair[M - i]{
34 | return (pIndex+1, iIndex+1)
35 | }
36 | if pair[i] == nil {
37 | pair[i] = iIndex
38 | }
39 | }
40 | return (-1, -1)
41 | }
42 | }
43 |
44 | /// https://www.hackerrank.com/challenges/maximise-sum
45 | public class MaximiseSum {
46 | func solution() {
47 | let T = getInt()
48 | for _ in 0.. Int {
84 | // use elements and modulo generate prefix table
85 | var prefix: [(Int, Int)] = Array(count: elements.count, repeatedValue: (0, 0))
86 | var current = 0
87 | var maxRet = 0
88 | for i in 0.. prefix[i+1].1 {
100 | if prefix[i+1].0 - prefix[i].0 < min {
101 | min = prefix[i+1].0 - prefix[i].0
102 | if min == 1 {
103 | break
104 | }
105 | }
106 | }
107 | }
108 | return max(maxRet, modulo - min)
109 | }
110 |
111 | /// Math behind the scene of modular
112 | /// (a + b) % M = (a % M + b % M) % M
113 | /// (a - b) % M = (a % M - b % M) % M
114 | /// Another important point to note is that to solve array related question, it is common to
115 | /// construct a prefix table.
116 | /// O(N^2)
117 | func slowSolve(modulo: Int, elements: [Int]) -> Int {
118 | // use elements and modulo generate prefix table
119 | var prefix: [Int] = Array(count: elements.count, repeatedValue: 0)
120 | var current = 0
121 | for i in 0.. prefix[i] {
131 | retVal = max(retVal, (prefix[i] - prefix[j] + modulo) % modulo)
132 | }
133 | }
134 | // prefix[i] means from beginning to i
135 | retVal = max(retVal, prefix[i])
136 | }
137 | return retVal
138 | }
139 | }
140 |
141 | /// https://www.hackerrank.com/challenges/sherlock-and-array
142 | public class SherlockAndArray {
143 | func solution() {
144 | let T = getInt()
145 | for _ in 0.. Bool {
158 | let arrCount = arr.count
159 | var leftSum = Array(count: arrCount + 1, repeatedValue: 0)
160 | for i in 1.. [String] {
184 | // According to the requirement, the difference's maximum is
185 | // 100. So if we take in an arbitrary number including itself
186 | // maximum count of this array is 201, expanding that number
187 | // to left and right by 100.
188 | var missArray = Array(count: 201, repeatedValue: 0)
189 | var baseArray = Array(count: 201, repeatedValue: 0)
190 | // Find the base, to index that array.
191 | let base = arrA[0] - 100
192 | var result = [Int]()
193 | arrA.forEach { i in
194 | let index = i - base
195 | missArray[index] += 1
196 | }
197 | arrB.forEach { i in
198 | let index = i - base
199 | baseArray[index] += 1
200 | }
201 | for (i, e) in baseArray.enumerate() {
202 | if e != missArray[i] {
203 | result.append(e)
204 | }
205 | }
206 | return result.map { String($0) }
207 | }
208 |
209 | func localTest() {
210 | if let testStreamReader = StreamReader(name: "missnumberinput", type: "txt") {
211 | let _ = testStreamReader.getInt()
212 | let a = testStreamReader.getLineToInts()
213 | let _ = testStreamReader.getInt()
214 | let b = testStreamReader.getLineToInts()
215 | logRunTime {
216 | print(self.solve(a, arrB:b))
217 | }
218 | }
219 | }
220 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | # HackerRankSolutions
8 |  [](https://travis-ci.org/jindulys/HackerRankSolutions) [](https://www.codewake.com/p/hackerranksolutions)
9 |
10 | This is a repo for [HackerRank](https://www.hackerrank.com/domains) Solutions in Swift
11 |
12 | Different folders are named after corresponding domain names or contest names.
13 |
14 | ## [Algorithms](Sources/)
15 | Problem | Time | Space | Difficulty | Tag | Note | Score | Max Score
16 | ---------------- | ---------------- | --------------- | ------------- |--------------| -----------| ---------| --------
17 | [Angry Professor](https://www.hackerrank.com/challenges/angry-professor) | _O(n)_ | | Easy | Implementation | | 20.0 | 20.0
18 | [SherlockAndTheBeast](https://www.hackerrank.com/challenges/sherlock-and-the-beast) | _O(n)_ | | Easy | Implementation| | 30.0 | 30.0
19 | [Utopian Tree](https://www.hackerrank.com/challenges/utopian-tree) | _O(n)_ | | Easy | Implementation | | 20.0 | 20.0
20 | [Find Digits](https://www.hackerrank.com/challenges/find-digits) | _O(n)_ | | Easy | Implementation | | 25.0 | 25.0
21 | [Funny String](https://www.hackerrank.com/challenges/funny-string) | _O(n)_ | | Easy | String | | 25.0 | 25.0
22 | [Pangrams](https://www.hackerrank.com/challenges/pangrams) | _O(n)_ | _O(1)_ | Easy | String | | 20.0 | 20.0
23 | [Alternating Characters](https://www.hackerrank.com/challenges/alternating-characters) | _O(n)_ | _O(1)_ | Easy | String | | 20.0 | 20.0
24 | [Game of Thrones](https://www.hackerrank.com/challenges/game-of-thrones) | _O(n)_ | _O(1)_ | Easy | String | | 30.0 | 30.0
25 | [Make it anagram](https://www.hackerrank.com/challenges/make-it-anagram) | _O(n)_ | _O(1)_ | Easy | String | | 30.0 | 30.0
26 | [Anagram](https://www.hackerrank.com/challenges/anagram) | _O(n)_ | _O(1)_ | Easy | String | | 14.29 | 25
27 | [Two Strings](https://www.hackerrank.com/challenges/two-strings) | _O(n)_ | _O(1)_ | Moderate | String | Set | 20.0 | 25.0
28 | [SherlockAndAnagrams](https://www.hackerrank.com/challenges/sherlock-and-anagrams) | _O(n^3lgn)_ | _O(n^2)_ | Moderate | String | Sort, Dictionary, Permutation | 4.55 | 50.0
29 | [Palindrome Index](https://www.hackerrank.com/challenges/palindrome-index) | _O(n)_ | _O(1)_ | Easy | String | | 25.0 | 25.0
30 | [Sherlock And Valid String](https://www.hackerrank.com/challenges/sherlock-and-valid-string) | _O(n)_ | _O(1)_ | Difficult | String | Dictionary | 100.0 | 100.0
31 | [Common Child](https://www.hackerrank.com/challenges/common-child) | _O(n^2)_ | _O(n^2)_ | Difficult | String | Dynamic Programming | 50.0 | 60.0
32 | [The Maximum Subarray](https://www.hackerrank.com/challenges/maxsubarray) | _O(n)_ | _O(n)_ | Easy | Dynamic Programming | | 16.67 | 50.0
33 | [The Coin Change Problem](https://www.hackerrank.com/challenges/coin-change) | _O(MN)_ | _O(MN)_ | Medium | Dynamic Programming | bottom-up table construction | 60.0 | 60.0
34 | [Red John is Back](https://www.hackerrank.com/challenges/red-john-is-back) | _O(N)_ + _O(nlgn)_ | _O(N)_ | Moderate | Dynamic Programming | memoization | 54.17 | 65
35 | [Knapsack](https://www.hackerrank.com/challenges/unbounded-knapsack) | _O(MN)_ | _O(MN)_ | Moderate | Dynamic Programming | memoization in swift | 54.06 | 60.0
36 | [Sam and SubStrings](https://www.hackerrank.com/challenges/sam-and-substrings) | _O(N)_ | _O(N)_ | Moderate | Dynamic Programming | | 40.0 | 40.0
37 | [The Longest Increasing Subsequence](https://www.hackerrank.com/challenges/longest-increasing-subsequent) | _O(N^2)_ | _O(N)_ | Advanced | Dynamic Programming | time out | 26.67 | 60.0
38 | [Hexagonal Gird](https://www.hackerrank.com/challenges/hexagonal-grid) | _O(N^2)_ | _O(N)_ | Moderate | Dynamic Programming | recursive solution | 70.0 | 70.0
39 | [Sherlock and Cost](https://www.hackerrank.com/challenges/sherlock-and-cost) | _O(N)_ | _O(N)_ | Moderate | Dynamic Programming | | 28.13 | 50.0
40 | [Dorsey Thief](https://www.hackerrank.com/challenges/dorsey-thief) | _O(NM)_ | _O(NM)_ | Advanced | Dynamic Programming | | 52.76| 85.0
41 | [Travel Around the World](https://www.hackerrank.com/challenges/travel-around-the-world) | _O(N)_ | _O(N)_ | Moderate | Dynamic Programming | validation pass and candidates finding pass | 120.0 | 120.0
42 | [Sherlock and Array](https://www.hackerrank.com/challenges/sherlock-and-array) | _O(N)_ | _O(N)_ | Easy | Search | | 40.0 | 40.0|
43 | [Ice Cream Parlor](https://www.hackerrank.com/challenges/icecream-parlor) | _O(N)_ | _O(N)_ | Easy | Search | | 30.0 | 30.0
44 | [Maximise Sum](https://www.hackerrank.com/challenges/maximise-sum) | _O(N)_ | _O(NlgN)_ | Moderate | Search | | 20.31 | 65.0
45 | [Missing Number](https://www.hackerrank.com/challenges/missing-numbers)| _O(N)_ | _O(N)_ | Moderate | Search| Do you believe 0.59s overtime? | 25.99 | 45
46 |
47 | ## Contests
48 | * [IndeedPrimeCodeSprint](https://www.hackerrank.com/contests/indeed-prime-codesprint/challenges)
49 | * [ZenefitsCodeSprint](https://www.hackerrank.com/contests/zenhacks/challenges)
50 |
51 | ## Data Structures in [HackerRankHelper](Sources/HackerRankHelper.swift)
52 | * FIFO Queue with Two Arraies
53 | * FIFO Queue with Listnode
54 | * ListNode
55 | * AVLNode
56 | * AVLTree
57 | * BinaryIndexedTree
58 | * Heap
59 |
60 | # Usage
61 |
62 | I created class for each problem. If you want to test those solution on HackerRank, please follow this guideline.
63 |
64 | 1. create a constant with class name.
65 |
66 | ```swift
67 | let mySolution = MyClass()
68 | ```
69 | 2. call *solution* method on that constant
70 |
71 | ```swift
72 | mySolution.solution()
73 | ```
74 |
75 | 3. copy and paste related helper methods from *HackerRankHelper* folder, eg. *getLine()*, *getInt()*
76 |
77 | # Swift Package Manager
78 |
79 | If you want to use this module to play with local test files, you might need to import this module. [Swift Package Manager](https://github.com/apple/swift-package-manager) is a good tool.
80 |
81 | Firstly, add following `Package.swift` to your root directory.
82 |
83 | ```swift
84 | import PackageDescription
85 |
86 | let package = Package(
87 | name:"YourModuleName",
88 | dependencies: [
89 | .Package(url:"https://github.com/jindulys/HackerRankSolutions.git", majorVersion:1),
90 | ]
91 | )
92 | ```
93 | Secondly, when you use this module in your source file, you should:
94 |
95 | ```swift
96 | import HRSwift
97 | ```
98 | Then run `swift build`, and `.build/debug/YourModuleName`, Alright, Run!!
99 |
100 | # Contribution Guidelines
101 |
102 | HackerRank lover, swift lover do not hesitate. There are tons of unsolved questions. If you want to contribute a little bit, please write your own swift solutions then make a pull request.
103 |
104 | For each question, you should write your own Class in corresponding file, inside that Class define a **solution** method, which is used for Hackerrank submission. This module could be imported by other packages, so make your class and those usable methods **public**. If you want to submit solution of **Algorithms** --> **Strings** --> **Gemstones**, you should write your solution inside [String.swift](Sources/Strings.swift). If there is no related file for a subdomain, please create a new file.
105 |
106 | Write a test case in [HRSwiftTests.swift](HRSwiftTests/HRSwiftTests.swift). You could use sample input and sample output from that question as a test.
107 |
108 | ```swift
109 | func testAnagram() {
110 | let test = Anagram()
111 | XCTAssert(test.solve("aaabbb") == 3, "Pass")
112 | XCTAssert(test.solve("ab") == 1, "Pass")
113 | XCTAssert(test.solve("abc") == -1, "Pass")
114 | }
115 | ```
116 |
117 | If you write some general code that could be used afterwards, please write them in [HackerRankHelper](Sources/HackerRankHelper.swift)
118 |
119 | Make sure your solution get a **reasonable score** on HackerRank then pull request.
120 |
121 | You should obey [Raywenderlich Swift Style Guide](https://github.com/raywenderlich/swift-style-guide)
122 |
123 |
--------------------------------------------------------------------------------
/HRSwiftTests/HRSwiftTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // HRSwiftTests.swift
3 | // HRSwiftTests
4 | //
5 | // Created by yansong li on 2015-11-20.
6 | // Copyright © 2015 yansong li. All rights reserved.
7 | //
8 |
9 | import XCTest
10 | @testable import HRSwift
11 |
12 | class HRSwiftTests: XCTestCase {
13 |
14 | override func setUp() {
15 | super.setUp()
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 | }
18 |
19 | override func tearDown() {
20 | // Put teardown code here. This method is called after the invocation of each test method in the class.
21 | super.tearDown()
22 | }
23 |
24 | func testExample() {
25 | // This is an example of a functional test case.
26 | // Use XCTAssert and related functions to verify your tests produce the correct results.
27 | }
28 |
29 | func testPerformanceExample() {
30 | // This is an example of a performance test case.
31 | self.measureBlock {
32 | // Put the code you want to measure the time of here.
33 | }
34 | }
35 |
36 | func testContainsAllEnglishCharacters() {
37 | let test1 = "abc"
38 | let test2 = "AbcdefghijklmnopqRstUVWxyZ"
39 | let test3 = "Abcdefghijkl mnopqRstUVWxyZ"
40 | let test4 = "The quick brown fox jumps over the lazy dog"
41 | XCTAssert(!test1.containsAllEnglishCharacters(), "Pass")
42 | XCTAssert(test2.containsAllEnglishCharacters(), "Pass")
43 | XCTAssert(test3.containsAllEnglishCharacters(), "Pass")
44 | XCTAssert(test4.containsAllEnglishCharacters(), "Pass")
45 | }
46 |
47 | func testContainsAllEnglishCharactersWithArray() {
48 | let test1 = "abc"
49 | let test2 = "AbcdefghijklmnopqRstUVWxyZ"
50 | let test3 = "Abcdefghijkl mnopqRstUVWxyZ"
51 | let test4 = "The quick brown fox jumps over the lazy dog"
52 | let mySolution = Pangrams()
53 | XCTAssert(!mySolution.checkPangramsWithArray(test1), "Pass")
54 | XCTAssert(mySolution.checkPangramsWithArray(test2), "Pass")
55 | XCTAssert(mySolution.checkPangramsWithArray(test3), "Pass")
56 | XCTAssert(mySolution.checkPangramsWithArray(test4), "Pass")
57 | }
58 |
59 | func testStringPalindrome() {
60 | let test1 = "aaa"
61 | let test2 = "abcd"
62 | let test3 = "afggfa"
63 | XCTAssert(test1.isPalindrome(), "Pass")
64 | XCTAssert(!test2.isPalindrome(), "Pass")
65 | XCTAssert(test3.isPalindrome(), "Pass")
66 | }
67 |
68 | func testQueueImplementation() {
69 | var queue = Queue()
70 | queue.enqueue("Yansong")
71 | queue.enqueue("Li")
72 | queue.enqueue("Great")
73 | XCTAssert(queue.dequeue() == .Some("Yansong"), "Pass")
74 | XCTAssert(queue.dequeue() == "Li", "Pass")
75 | XCTAssert(queue.dequeue() == "Great", "Pass")
76 | }
77 |
78 | func testHexagonalGrid() {
79 | let test = HexagonalGrid()
80 | var testGrid1 = [[0,0], [0,0]]
81 | var testGrid2 = [[0,0], [1,0]]
82 | var testGrid3 = [[0,0], [0,1]]
83 | var testGrid4 = [[0,0], [1,1]]
84 | var testGrid5 = [[1,0], [0,0]]
85 | var testGrid6 = [[1,0], [1,0]]
86 | var testGrid7 = [[1,0], [0,1]]
87 | XCTAssert(test.rec(&testGrid1),"Pass")
88 | XCTAssert(!test.rec(&testGrid2),"Pass")
89 | XCTAssert(!test.rec(&testGrid3),"Pass")
90 | XCTAssert(test.rec(&testGrid4),"Pass")
91 | XCTAssert(!test.rec(&testGrid5),"Pass")
92 | XCTAssert(test.rec(&testGrid6),"Pass")
93 | XCTAssert(test.rec(&testGrid7),"Pass")
94 | }
95 |
96 | func testSamAndSubStrings() {
97 | let test = SamAndSubString()
98 | XCTAssert(test.solve("16") == 23, "Pass")
99 | }
100 |
101 | func testTravelAroundTheWorld() {
102 | let test = TravelAroundTheWorld()
103 | XCTAssert(test.solve(3, a: [3,1,2], b: [2,2,2]) == 2, "Pass")
104 | }
105 |
106 | func testRedJohnisBack() {
107 | let test = RedJohnisBack()
108 | XCTAssert(test.solve(7) == 3, "Pass")
109 | XCTAssert(test.solve(38) == 10794, "Pass")
110 | }
111 |
112 | func testDorsyThief() {
113 | let test = DorseyThief()
114 | let passenger1 = Passenger(offer: 460, weight: 4)
115 | let passenger2 = Passenger(offer: 590, weight: 6)
116 | let passenger3 = Passenger(offer: 590, weight: 5)
117 | let passenger4 = Passenger(offer: 550, weight: 5)
118 | XCTAssertTrue(test.solve([passenger1, passenger2, passenger3, passenger4], c: 10) == 1140)
119 | }
120 |
121 | func testAlternatingCharacters() {
122 | let test = AlternatingCharcters()
123 | XCTAssertTrue(test.solve("ABAA") == 1)
124 | }
125 |
126 | func testMakeItAnagram() {
127 | let test = MakeItAnagram()
128 | XCTAssertTrue(test.solve("cde", line2: "abc")==4)
129 | }
130 |
131 | func testAnagram() {
132 | let test = Anagram()
133 | XCTAssert(test.solve("aaabbb") == 3, "Pass")
134 | XCTAssert(test.solve("ab") == 1, "Pass")
135 | XCTAssert(test.solve("abc") == -1, "Pass")
136 | }
137 |
138 | func testSherlockAndAnagrams() {
139 | let test = SherlockAndAnagrams()
140 | XCTAssert(test.solve("abba") == 4, "Pass")
141 | }
142 |
143 | func testCommonChile() {
144 | let test = CommonChild()
145 | XCTAssert(test.solve("ABCD", second: "ABDC") == 3, "Pass")
146 | }
147 |
148 | func testFibonacci() {
149 | let fib: (Int)->Int = memoize { (fib, x) in
150 | if x < 2 {
151 | return x
152 | }
153 | return fib(x-1) + fib(x-2)
154 | }
155 | XCTAssert(fib(8) == 21, "Pass")
156 | }
157 |
158 | func testHeap() {
159 | var testHeap = MaxHeap(array: [1, 2, 3, 5, 7, 10])
160 | XCTAssert(testHeap.peak()! == 10, "Pass")
161 | testHeap.insert(61)
162 | XCTAssert(testHeap.peak()! == 61, "Pass")
163 |
164 | let emptyHeap = MaxHeap()
165 | XCTAssert(emptyHeap.peak() == nil, "Pass")
166 | }
167 |
168 | func testHeapInsertRemove() {
169 | /** 9
170 | * 7 5
171 | * 1 2 3
172 | * Should be represented in memory as [9, 5, 7, 1, 3, 2] though we are just testing the effects.
173 | */
174 | var heap = MaxHeap(array: [1, 3, 2, 7, 5, 9])
175 |
176 | //Should be removed in order
177 | XCTAssertEqual(9, heap.remove())
178 | XCTAssertEqual(7, heap.remove())
179 | XCTAssertEqual(5, heap.remove())
180 | XCTAssertEqual(3, heap.remove())
181 | XCTAssertEqual(2, heap.remove())
182 | XCTAssertEqual(1, heap.remove())
183 | XCTAssertNil(heap.remove())
184 | }
185 |
186 | func testHeapCount() {
187 | var heap = MaxHeap()
188 | XCTAssertEqual(0, heap.count)
189 | heap.insert(1)
190 | XCTAssertEqual(1, heap.count)
191 | }
192 |
193 | func testHeapRemoveEmpty() {
194 | var heap = MaxHeap()
195 | let removed = heap.remove()
196 | XCTAssertNil(removed)
197 | }
198 |
199 | func testBinarySearch() {
200 | let a = [1, 2, 10, 18, 19, 66, 88]
201 | XCTAssertEqual(0, binarySearch(a, key: 1, range: 0.. 0 }
310 | XCTAssertEqual(tn3, [])
311 | }
312 | }
313 |
--------------------------------------------------------------------------------
/Sources/Strings.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Strings.swift
3 | // HRSwift
4 | //
5 | // Created by yansong li on 2015-11-29.
6 | // Copyright © 2015 yansong li. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | // https://www.hackerrank.com/challenges/pangrams
12 | public class Pangrams {
13 |
14 | public init() {}
15 |
16 | func solution() {
17 | checkPangramsWithSet(getLine())
18 | }
19 |
20 | /**
21 | CheckPangramsWithSet
22 |
23 | - parameter s: string to check
24 | */
25 | public func checkPangramsWithSet(s: String) {
26 | if s.containsAllEnglishCharacters() {
27 | print("pangram")
28 | } else {
29 | print("not pangram")
30 | }
31 | }
32 |
33 | func checkPangramsWithArray(s: String) -> Bool {
34 | var indexArray = [Bool](count: 26, repeatedValue: false)
35 | let a: Character = "a"
36 |
37 | for c in s.characters {
38 | let lowerCs = String(c).lowercaseString.characters
39 | let lowerC = lowerCs[lowerCs.startIndex]
40 | let index = lowerC.unicodeScalarCodePoint() - a.unicodeScalarCodePoint()
41 | switch index {
42 | case 0..<26:
43 | indexArray[index] = true
44 | default:
45 | continue
46 | }
47 | }
48 |
49 | let result = indexArray.reduce(true){result,current in result && current}
50 | if result {
51 | print("pangram")
52 | } else {
53 | print("not pangram")
54 | }
55 |
56 | // Return result for unit testing
57 | return result
58 | }
59 | }
60 |
61 | // https://www.hackerrank.com/challenges/funny-string
62 |
63 | public class FunnyString {
64 |
65 | public init() {}
66 |
67 | func solution() -> Void {
68 | let T = getInt()
69 | for _ in 0.. Void {
86 | var values = [Int]()
87 | var reversed = [Int]()
88 |
89 | let count = s.characters.count
90 | for (i, c) in s.characters.enumerate() {
91 | values.append(c.unicodeScalarCodePoint())
92 | let reversedIndex = s.characters.startIndex.advancedBy(count - i.successor(), limit: s.characters.endIndex)
93 | reversed.append(s.characters[reversedIndex].unicodeScalarCodePoint())
94 | }
95 |
96 | var isFunny = true
97 | for i in 1.. Void {
117 | var values = [Int]()
118 | var reversed = [Int]()
119 |
120 | let count = s.characters.count
121 |
122 | for (_, c) in s.characters.enumerate() {
123 | values.append(c.unicodeScalarCodePoint())
124 | }
125 |
126 | for (_, c) in s.characters.reverse().enumerate() {
127 | reversed.append(c.unicodeScalarCodePoint())
128 | }
129 |
130 | var isFunny = true
131 | for i in 1.. Int {
159 | var previous = input.characters.first!
160 | var currentIndex = input.characters.startIndex.successor()
161 | var toDelete = 0
162 | while currentIndex != input.characters.endIndex {
163 | let current = input.characters[currentIndex]
164 | if current == previous {
165 | toDelete += 1
166 | }
167 | previous = current
168 | currentIndex = currentIndex.successor()
169 | }
170 | print("\(toDelete)")
171 | return toDelete
172 | }
173 | }
174 |
175 | public class GameofThrones {
176 |
177 | public init() {}
178 |
179 | func solution() {
180 | let input = getLine()
181 | solve(input)
182 | }
183 |
184 | public func solve(input: String) -> Bool {
185 | var charactersArray = Array(count: 26, repeatedValue: 0)
186 | for c in input.characters {
187 | let currentIndex = c.unicodeScalarCodePoint() - 97
188 | charactersArray[currentIndex] = charactersArray[currentIndex] + 1
189 | }
190 | let oddCount = charactersArray.filter { $0%2 == 1 }.count
191 | if oddCount > 1 {
192 | print("NO")
193 | return false
194 | } else {
195 | print("YES")
196 | return true
197 | }
198 | }
199 | }
200 |
201 | public class MakeItAnagram {
202 |
203 | public init() {}
204 |
205 | func solution() {
206 | let line1 = getLine()
207 | let line2 = getLine()
208 |
209 | solve(line1, line2: line2)
210 | }
211 |
212 | public func solve(line1: String, line2: String) -> Int {
213 | var line1Counts = Array(count: 26, repeatedValue: 0)
214 | var line2Counts = Array(count: 26, repeatedValue: 0)
215 |
216 | for c in line1.characters {
217 | let currentIndex = c.unicodeScalarCodePoint() - 97
218 | line1Counts[currentIndex] = line1Counts[currentIndex] + 1
219 | }
220 |
221 | for c in line2.characters {
222 | let currentIndex = c.unicodeScalarCodePoint() - 97
223 | line2Counts[currentIndex] = line2Counts[currentIndex] + 1
224 | }
225 |
226 | var sum = 0
227 | for i in 0..<26 {
228 | sum += abs(line1Counts[i] - line2Counts[i])
229 | }
230 | print(sum)
231 | return sum
232 | }
233 | }
234 |
235 | public class Anagram {
236 |
237 | public init() {}
238 |
239 | func solution() {
240 | let T = getInt()
241 | for _ in 0.. Int {
248 | if input.characters.count % 2 != 0 {
249 | print("-1")
250 | return -1
251 | }
252 |
253 | let count = input.characters.count
254 | // Use string index to operate on String
255 | let midIndex = input.startIndex.advancedBy(count/2)
256 |
257 | let a = input.substringToIndex(midIndex)
258 | let b = input.substringFromIndex(midIndex)
259 |
260 | var aCharacters = Array(count: 26, repeatedValue: 0)
261 | var bCharacters = Array(count: 26, repeatedValue: 0)
262 |
263 | for c in a.characters {
264 | let currentIndex = c.unicodeScalarCodePoint() - 97
265 | aCharacters[currentIndex] += 1
266 | }
267 |
268 | for c in b.characters {
269 | let currentIndex = c.unicodeScalarCodePoint() - 97
270 | bCharacters[currentIndex] += 1
271 | }
272 |
273 | var sum = 0
274 | for i in 0..<26 {
275 | sum += abs(aCharacters[i] - bCharacters[i])
276 | }
277 |
278 | print("\(sum/2)")
279 | return sum/2
280 | }
281 | }
282 |
283 | // https://www.hackerrank.com/challenges/two-strings
284 | public class TwoStrings {
285 |
286 | public init() {}
287 |
288 | func solution() {
289 | let T = getInt()
290 | for _ in 0.. Bool {
298 | let sSet = s.convertToCharacterSet()
299 | let tSet = t.convertToCharacterSet()
300 |
301 | let intersections = sSet.intersect(tSet)
302 | let results = intersections.count > 0
303 | if results {
304 | print("YES")
305 | } else {
306 | print("NO")
307 | }
308 | return results
309 | }
310 | }
311 |
312 | public class SherlockAndAnagrams {
313 |
314 | public init() {}
315 |
316 | func solution() {
317 | let T = getInt()
318 | for _ in 0.. Int {
325 | // Generate all possible substrings, which requires O(n^2) time.
326 | let N = input.characters.count
327 | var subStringDict = [String: Int]()
328 | var currentIndex = input.characters.startIndex
329 | for i in SRange(end: N) {
330 | for l in SRange(start: 1, end: N-i+1) {
331 | let endIndex = currentIndex.advancedBy(l)
332 | let subString = input.substringWithRange(Range(start: currentIndex, end: endIndex))
333 |
334 | //let sortedSubString = String(Array(subString.characters).sort())
335 |
336 | // This solution might slightly improve performance
337 | let sortedSubString = String(Array(subString.utf16).sort())
338 |
339 | if let currentSubStringCount = subStringDict[sortedSubString] {
340 | subStringDict[sortedSubString] = currentSubStringCount + 1
341 | } else {
342 | subStringDict[sortedSubString] = 1
343 | }
344 | }
345 | currentIndex = currentIndex.advancedBy(1)
346 | }
347 |
348 | var sum = 0
349 | for value in subStringDict.values {
350 | sum += value * (value - 1) / 2
351 | }
352 | print(sum)
353 | return sum
354 | }
355 | }
356 |
357 | // https://www.hackerrank.com/challenges/palindrome-index
358 | public class PalindromeIndex {
359 |
360 | public init() {}
361 |
362 | func solution() {
363 | let T = getInt()
364 | for _ in 0.. 2 {
425 | print("NO")
426 | } else if countsOccurrence.keys.count == 2 {
427 | let keys = [Int](countsOccurrence.keys)
428 | let bigKey = max(keys[0], keys[1])
429 | let smallKey = min(keys[0], keys[1])
430 |
431 | // case 1 we could always remove smallkey that only occur 1 and count is 1
432 | // case 2 the difference of occurence is 1 and bigkey is only 1 element
433 | if (smallKey*countsOccurrence[smallKey]! == 1 ||
434 | (abs(keys[0] - keys[1]) == 1 && countsOccurrence[bigKey]! == 1)) {
435 | print("YES")
436 | } else {
437 | print("NO")
438 | }
439 | } else {
440 | print("YES")
441 | }
442 | }
443 | }
444 |
445 | public class CommonChild {
446 |
447 | public init() {}
448 |
449 | func solution() {
450 | let a = getLine()
451 | let b = getLine()
452 | solve(a, second: b)
453 | }
454 |
455 | /**
456 | Solve this problem use dynamic programming.
457 |
458 | The basic idea is that we could take current character if current one and test one are equal, otherwise we
459 | could choose max from
460 |
461 | (1) take this character and dont take test one
462 |
463 | (2) take the test one and ignore current one
464 |
465 | dp[i][j] = dp[i-1][j-1] + 1 if first[i] == first[j]
466 | dp[i][j] = max(dp[i][j-1], dp[i-1][j]) if first[i] != first[j]
467 |
468 | - parameter first: input one
469 | - parameter second: input two
470 |
471 | - returns: the length of longest subString of both inputs
472 | */
473 | public func solve(first: String, second: String) -> Int {
474 | let N = first.characters.count
475 | // Construct a N+1 by N+1 matrix so we could deal with 0 element.
476 | var dp = Array(count: N+1, repeatedValue: Array(count: N+1, repeatedValue: 0))
477 |
478 | // Swift string do not support subscript so we should use index instead.
479 | var currentFirstIndex = first.characters.startIndex
480 | for i in 1.. Void {
22 | // This way to get rid of redundant cost
23 | let length = cashes.count
24 | if cost == 0 {
25 | combinations.append(valueList)
26 | }
27 | for i in start.. Int {
38 | if n < 0 {
39 | return 0
40 | }
41 | if n == 0 {
42 | return 1
43 | }
44 | if i == 7{
45 | return 0
46 | }
47 |
48 | var ans = 0
49 | ans += call(i, n: n-cashes[i]) + call(i+1, n: n)
50 | return ans
51 | }
52 |
53 | func solution() -> Void {
54 | let cost = Int(getLine())!
55 | //getNumOfCost(cost, start: 0, valueList: [])
56 | //print(combinations.count)
57 | print(call(0, n: cost))
58 | }
59 | }
60 |
61 |
62 | // Question 2
63 |
64 | class EncryptionModule {
65 | let p: String
66 | let ePrime: String
67 | var shiftCounts: [Int:Int]
68 |
69 | init(p:String, ep:String) {
70 | self.p = p
71 | self.ePrime = ep
72 | shiftCounts = [Int: Int]()
73 | }
74 |
75 | // wrong one because I forgot to count recycle of shift
76 | // func calculateShifting() -> Void {
77 | // for (i, c) in p.characters.enumerate() {
78 | // let currentDetectIndex = ePrime.characters.startIndex.advancedBy(i)
79 | // let characterToCompare = ePrime.characters[currentDetectIndex]
80 | // let toCompare = characterToCompare.unicodeScalarCodePoint()
81 | // let compared = c.unicodeScalarCodePoint()
82 | // if let val = shiftCounts[toCompare - compared] {
83 | // shiftCounts[toCompare - compared] = val + 1
84 | // } else {
85 | // shiftCounts[toCompare - compared] = 1
86 | // }
87 | // }
88 | // var minimal = Int.min
89 | // for (_, counts) in shiftCounts {
90 | // if minimal < counts {
91 | // minimal = counts
92 | // }
93 | // }
94 | // print(shiftCounts)
95 | // print(p.characters.count - minimal)
96 | // }
97 |
98 | func calculateShifting() -> Void {
99 | for (i, c) in p.characters.enumerate() {
100 | let currentDetectIndex = ePrime.characters.startIndex.advancedBy(i)
101 | let characterToCompare = ePrime.characters[currentDetectIndex]
102 | let toCompare = characterToCompare.unicodeScalarCodePoint()
103 | let compared = c.unicodeScalarCodePoint()
104 | if let val = shiftCounts[toCompare - compared] {
105 | shiftCounts[toCompare - compared] = val + 1
106 | } else {
107 | shiftCounts[toCompare - compared] = 1
108 | }
109 | }
110 | var final = [Int: Int]()
111 | for (k, v) in shiftCounts {
112 |
113 | print("key:\(k), value:\(v)")
114 | let reverseKey = k > 0 ? k-26 : 26+k
115 |
116 | if let _ = final[k] {
117 | continue
118 | }
119 |
120 | if let _ = final[reverseKey] {
121 | continue
122 | }
123 |
124 | var countTotal = v
125 | if let val = shiftCounts[reverseKey] {
126 | countTotal += val
127 | }
128 |
129 | final[k] = countTotal
130 | }
131 | var minimal = Int.min
132 | for (_, counts) in final {
133 | if minimal < counts {
134 | minimal = counts
135 | }
136 | }
137 | print(final)
138 | print(p.characters.count - minimal)
139 | }
140 | }
141 |
142 | // Question 3
143 |
144 | class jarjarBinks {
145 | // This question want me to find pair of shoes that matches
146 |
147 | func getPairOfShoes(pairs:[(String, String)]) -> Void {
148 | var matches = [String:[String:Int]]()
149 | for (des, type) in pairs {
150 | if var savedType = matches[des] {
151 | if let typeCount = savedType[type] {
152 | savedType[type] = typeCount + 1
153 | } else {
154 | savedType[type] = 1
155 | }
156 | matches[des] = savedType
157 | } else {
158 | matches[des] = [type: 1]
159 | }
160 | }
161 |
162 | var totalMatches = 0
163 | for (_, savedType) in matches {
164 | if savedType.keys.count == 2 {
165 | var lessCount = Int.max
166 | for (_, count) in savedType {
167 | if count < lessCount {
168 | lessCount = count
169 | }
170 | }
171 | totalMatches += lessCount
172 | }
173 | }
174 | print(totalMatches)
175 | }
176 |
177 |
178 | func solution() -> Void {
179 | let N = Int(getLine())!
180 | var inputs = [(String, String)]()
181 | for _ in 0.. Void {
193 | let myPairs = [("nike4blue","L"),("adidas4green","L"),("nike4blue","R")]
194 | getPairOfShoes(myPairs)
195 | }
196 | }
197 |
198 | // Question 4
199 |
200 | class PrimeTargets {
201 |
202 | var currentPrimes = [Int]()
203 | func solution() -> Void {
204 | let N = Int(getLine())!
205 | let inputs = getLine().componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).map{Int($0)!}
206 | getPrimesSumBetter(inputs,count: N)
207 | }
208 |
209 | // This solution has time out
210 |
211 | func getPrimesSum(inputs:[Int], count:Int) -> Void {
212 | let primes = getPrimes(count)
213 | var total = 0
214 | for i in 0.. Void {
235 | let primes = getPrimes(count)
236 | currentPrimes = primes
237 | var total = 0
238 | for i in 0.. [Int] {
249 | // Here the length means how many elements we have
250 | // This prime finder is a specific one because we want to find gap that is prime
251 | // so we start from 3
252 | var primes = [Int]()
253 | if length < 3 {
254 | return primes
255 | }
256 |
257 | // here since we want to find gap, length should not be included, start from 2 since 2 is the smallest prime
258 | for i in 2..= 2 {
265 | for j in 2...intHigher {
266 | if i % j == 0 {
267 | currentIsPrime = false
268 | break
269 | }
270 | }
271 | }
272 |
273 | if currentIsPrime {
274 | primes.append(i)
275 | }
276 | }
277 | return primes
278 | }
279 |
280 | func binarySearchLessOrEqualIndex(target:Int) -> Int {
281 | var lowerIndex = 0
282 | var higherIndex = currentPrimes.count - 1
283 |
284 | var indexToCheck = (higherIndex + lowerIndex) / 2
285 | while lowerIndex <= higherIndex {
286 | if currentPrimes[indexToCheck] == target {
287 | return indexToCheck + 1
288 | } else if (currentPrimes[indexToCheck] < target) {
289 | lowerIndex = indexToCheck + 1
290 | indexToCheck = (higherIndex + lowerIndex) / 2
291 | } else {
292 | higherIndex = indexToCheck - 1
293 | indexToCheck = (higherIndex + lowerIndex) / 2
294 | }
295 | }
296 |
297 | // At this point our lower exceed higher
298 | return higherIndex + 1
299 | }
300 |
301 | func test() -> Void {
302 | getPrimesSumBetter([2, 4, 6, 8, 10, 12, 14], count: 7)
303 | }
304 | }
305 |
306 | // Question 9
307 |
308 |
309 | // https://www.hackerrank.com/contests/zenhacks/challenges/zenland
310 | class BattleOfRyloth {
311 | // required person at Node[i]
312 | var required = [Int](count: 100000, repeatedValue: 0)
313 | // available person at Node[i]
314 | var available = [Int](count: 100000, repeatedValue: 0)
315 | // degree of node i in given tree
316 | var degree = [Int](count: 100000, repeatedValue: 0)
317 | // Adjacency list of Node
318 | var graph = [[Int]](count: 100000, repeatedValue: [])
319 | // Queue to store all the leaves
320 | var leafNodes = Queue()
321 |
322 | // Used LinkedListQueue to try to improve performance, failed
323 | var leafNodes2 = LinkedListQueue()
324 |
325 |
326 | func solution() {
327 | let numberOfNodes = Int(getLine())!
328 | for i in 0..= coins[r] ? resultTable[r][c - coins[r]]: 0
47 | let withoutUsingCurrentCoin = r > 0 ? resultTable[r-1][c] : 0
48 | resultTable[r][c] = useCurrentCoin + withoutUsingCurrentCoin
49 | }
50 | }
51 | print(resultTable[coinsCounts-1][total])
52 | }
53 | }
54 |
55 | public class MaximumSubArray {
56 |
57 | public init() {}
58 |
59 | func solution() {
60 | let T = Int(getLine())!
61 | for _ in 0.. 0}.reduce(0) {total, num in total + num}
76 |
77 | // contiguous subarray
78 | var currentMax = 0
79 | var currentSum = 0
80 | for i in 0.. currentMax { currentMax = currentSum }
86 | }
87 |
88 | print("\(currentMax) \(nonContiguous)")
89 | }
90 | }
91 |
92 | // Implement KnapSackPair because our memoize function only take one type which is hashable for input
93 | struct KnapSackPair {
94 | var itemIndex: Int
95 | var capacity: Int
96 | }
97 |
98 | extension KnapSackPair : Hashable {
99 | var hashValue : Int {
100 | get {
101 | return itemIndex.hashValue + capacity.hashValue
102 | }
103 | }
104 | }
105 |
106 | func ==(lhs: KnapSackPair, rhs: KnapSackPair) -> Bool {
107 | return lhs.itemIndex == rhs.itemIndex && lhs.capacity == rhs.capacity
108 | }
109 |
110 | public class Knapsack {
111 |
112 | public init() {}
113 |
114 | func solution() {
115 | let T = getInt()
116 | for _ in 0..Int = memoize{ knapsack, knapSackPair in
133 | let i = knapSackPair.itemIndex
134 | let k = knapSackPair.capacity
135 |
136 | if i < 1 { return 0 }
137 | // not choose current item
138 | let upperValue = knapsack(KnapSackPair(itemIndex: i - 1, capacity: k))
139 |
140 | // choose current item more than 1 time
141 | let leftValue = k < array[i-1] ? 0 : knapsack(KnapSackPair(itemIndex: i, capacity: k - array[i-1])) + array[i - 1]
142 |
143 | // choose current item for the first time
144 | let leftUpperValue = k < array[i-1] ? 0 : knapsack(KnapSackPair(itemIndex: i-1, capacity: k - array[i-1])) + array[i - 1]
145 |
146 | let bigger = max(upperValue, leftValue)
147 |
148 | return max(bigger, leftUpperValue)
149 | }
150 |
151 | print(knapsack(KnapSackPair(itemIndex: N, capacity: K)))
152 | }
153 | }
154 |
155 | public class LongestIncreasingSubsequence {
156 |
157 | public init() {}
158 |
159 | func solution() {
160 | let N = getInt()
161 | let array = getLinesToArray(N).map { Int($0)! }
162 | betterSolve(array)
163 | }
164 |
165 | /**
166 | * Construct LIS(longestIncreasingSubsequence) for each i, which ends at ith element of the array.
167 | * LIS[i] = max(LIS)
168 | * time efficiency O(n^2)
169 | */
170 | public func solve(array:[Int]) {
171 | let N = array.count
172 | var LIS = Array(count: N, repeatedValue: 0)
173 | LIS[0] = 1
174 | for i in 1.. LIS[i] {
178 | LIS[i] = LIS[j] + 1
179 | atLeastFindOne = true
180 | }
181 | }
182 | if !atLeastFindOne { LIS[i] = 1}
183 | }
184 |
185 | let maximum = LIS.reduce(0) {result, current in
186 | return current > result ? current : result
187 | }
188 | print("\(maximum)")
189 | }
190 |
191 | /**
192 | * http://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/
193 | */
194 | func betterSolve(array:[Int]) {
195 | let N = array.count
196 | // Auxiliary array to store each appropriate end element
197 | var endElements = Array(count: N, repeatedValue: 0)
198 | endElements[0] = array[0]
199 | var len = 1
200 |
201 | for i in 1.. endElements[len - 1] {
206 | // extend endElements array
207 | len += 1
208 | endElements[len - 1] = array[i]
209 | } else {
210 | // replace the smallest element that is larger than array[i]
211 | endElements[ceilIndex(endElements, l: -1, r: len - 1, key: array[i])] = array[i]
212 | }
213 | }
214 | print("\(len)")
215 | }
216 | }
217 |
218 | public class SherlockAndCost {
219 |
220 | public init() {}
221 |
222 | func solution() {
223 | let T = getInt()
224 | for _ in 0.. Bool {
296 | let m = grid.count
297 | let n = grid[0].count
298 |
299 | var changed = false
300 | for i in 0..= 0 && nextI < m && nextJ >= 0 && nextJ < n && grid[nextI][nextJ] == 0 {
310 | grid[nextI][nextJ] = 1
311 | if rec(&grid) { return true }
312 | grid[nextI][nextJ] = 0
313 | }
314 | }
315 | grid[i][j] = 0
316 | }
317 | }
318 | }
319 | }
320 |
321 | return !changed
322 | }
323 | }
324 |
325 | public class SamAndSubString {
326 |
327 | public init() {}
328 |
329 | static let MOD = Int(1e9 + 7)
330 |
331 | func solution() {
332 | let input = getLine()
333 | solve(input)
334 | }
335 |
336 | public func solve(input:String) -> Int {
337 | let N = input.characters.count
338 | var preSum = Array(count: N, repeatedValue: 0)
339 | preSum[0] = Int(String(input.characters.first!))!
340 | var i = 1
341 | var currentIndex = input.characters.startIndex.successor()
342 | /**
343 | * each time when we add a new element, there is a relationship between previous sum and current sum
344 | */
345 | while currentIndex != input.characters.endIndex {
346 | preSum[i] = (preSum[i-1]*10 + Int(String(input.characters[currentIndex]))!*(i+1))%SamAndSubString.MOD
347 | i += 1
348 | currentIndex = currentIndex.successor()
349 | }
350 | let retVal = preSum.reduce(0) { total, currentE in
351 | let newTotal = (total + currentE) % SamAndSubString.MOD
352 | return newTotal
353 | }
354 | print(retVal)
355 | return retVal
356 | }
357 | }
358 |
359 | public class TravelAroundTheWorld {
360 |
361 | public init() {}
362 |
363 | func solution() {
364 | let metrics = getLineToArray().map { Int($0)! }
365 | let a = getLineToArray().map() { Int($0)! }
366 | let b = getLineToArray().map() { Int($0)! }
367 | solve(metrics[1], a: a, b: b)
368 | }
369 |
370 | /**
371 | * we should solve this problem in two part
372 | * (1) the first part we should ensure that we could find a suitable start city
373 | * the idea is that, if we start from city s, then if it is viable(current fuel left + a[i] - b[i] > 0),
374 | * then we move to next city s+1 and so on, until we reach a city s + j, where we dont have enough fuel,
375 | * then we should start from s+j and continue looking. if there is no such city, then we have no solution
376 | * to travel the whole world.
377 | * (2) If we find some suitable start point s, we could consider the city before it could work or not.
378 | * let need[i] means at city i, the need of fuel to next city.
379 | * we have the formula need[i] = max(0, need[i+1] + b[i] - min(capacity, a[i]))
380 | * all of the city with need[i] == 0 is suitable start point
381 | *
382 | */
383 | public func solve(c:Int, a:[Int], b:[Int]) -> Int {
384 | let N = a.count
385 | var earthA = Array(count: 2*N, repeatedValue: 0)
386 | var earthB = Array(count: 2*N, repeatedValue: 0)
387 |
388 | for i in 0..= n, which means we could not find a city within n-1, that could walk through the whole map
419 | if s >= N {
420 | print("0")
421 | return 0
422 | } else {
423 | // check other potential start positions
424 | retVal = 1
425 | need[s+N] = 0
426 | for i in 1.. Int {
452 | let fibOneAndFour: (Int)->Int = memoize { fibOneAndFour, n in
453 | if n>=1 && n<=3 {
454 | return 1
455 | }
456 | if n == 4 {
457 | return 2
458 | }
459 |
460 | return fibOneAndFour(n-1) + fibOneAndFour(n-4)
461 | }
462 | let combinations = fibOneAndFour(n)
463 | let primes = getBetterPrimes(combinations)
464 | print(primes.count)
465 | return primes.count
466 | }
467 | }
468 |
469 | /**
470 | * Struct Passenger to store information like offer value and accept weight of gold
471 | * Using struct here is for sorting
472 | */
473 | public struct Passenger {
474 | let offer: Int
475 | let weight: Int
476 | }
477 |
478 | extension Passenger : Hashable {
479 | public var hashValue : Int {
480 | get {
481 | return offer.hashValue + weight.hashValue
482 | }
483 | }
484 | }
485 |
486 | extension Passenger : CustomStringConvertible {
487 | public var description: String { return "Passenger offer \(offer) for \(weight)grams" }
488 | }
489 |
490 | public func ==(lhs: Passenger, rhs: Passenger) -> Bool {
491 | return lhs.offer == rhs.offer && lhs.weight == rhs.weight
492 | }
493 |
494 | let LOWESTNUMBER = -1 * NSIntegerMax
495 |
496 | public class DorseyThief {
497 |
498 | public init() {}
499 |
500 | func solution() {
501 | let metrics = getLineToArray().map { Int($0)! }
502 | var array: [Passenger] = []
503 | for _ in 0..Int {
512 | // sort the input array
513 | let sortedArray = array.sort { p1, p2 in
514 | if p1.offer == p2.offer {
515 | return p1.weight > p2.weight
516 | }
517 | return p1.offer > p2.offer
518 | }
519 |
520 | var offersByAmount = [LinkedListQueue]()
521 | for _ in 0..())
523 | }
524 | for passenger in sortedArray {
525 | if passenger.weight <= c {
526 | let currentQueue = offersByAmount[passenger.weight-1]
527 | // Thief could not sell that much, here is the limitation. this is the key for optimization
528 | if currentQueue.count < c/passenger.weight {
529 | currentQueue.enqueue(passenger)
530 | }
531 | }
532 | }
533 |
534 | var offers: [Passenger] = []
535 | for offerList in offersByAmount {
536 | while !offerList.isEmpty() {
537 | offers.append(offerList.dequeue()!)
538 | }
539 | }
540 |
541 | let N = offers.count
542 |
543 | var K = Array(count: N+1, repeatedValue: Array(count: c+1, repeatedValue: 0))
544 |
545 | for x in 1..= 0 ? K[i-1][x - a_i] : LOWESTNUMBER
555 | K[i][x] = max(K[i-1][x], t + v_i)
556 | }
557 | }
558 |
559 | if K[N][c] < 0 {
560 | print("Got caught!")
561 | } else {
562 | print(K[N][c])
563 | }
564 | return K[N][c]
565 | }
566 | }
567 |
568 |
569 |
570 |
571 |
--------------------------------------------------------------------------------
/HRSwift.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 0E2C0C941D565C9700748BAF /* 105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2C0C931D565C9700748BAF /* 105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift */; };
11 | 0E2C0C961D56714500748BAF /* 106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2C0C951D56714500748BAF /* 106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift */; };
12 | 0E2C0C981D5680B800748BAF /* 113_PathSumII.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2C0C971D5680B800748BAF /* 113_PathSumII.swift */; };
13 | 0E2C0C9A1D56973300748BAF /* 98_ValidateBinarySearchTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2C0C991D56973300748BAF /* 98_ValidateBinarySearchTree.swift */; };
14 | 0E2C0C9D1D56A18700748BAF /* 290_WordPattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2C0C9C1D56A18700748BAF /* 290_WordPattern.swift */; };
15 | 0E2C0C9F1D56E4F900748BAF /* 344_ReverseString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2C0C9E1D56E4F900748BAF /* 344_ReverseString.swift */; };
16 | 0E2C0CA11D56E9A700748BAF /* 345_ReverseVowelsOfAString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2C0CA01D56E9A700748BAF /* 345_ReverseVowelsOfAString.swift */; };
17 | 0E2DFC361C604E9200644A7B /* Int+HRSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2DFC351C604E9200644A7B /* Int+HRSwift.swift */; };
18 | 0E3C7E381D542BB200D6550A /* 337_HouseRobberIII.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3C7E371D542BB200D6550A /* 337_HouseRobberIII.swift */; };
19 | 0E3C7E3A1D54431100D6550A /* 102_BinaryTreeLevelOrderTraversal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3C7E391D54431100D6550A /* 102_BinaryTreeLevelOrderTraversal.swift */; };
20 | 0E5112D61CCC6C2500948DC0 /* Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E5112D31CCC6C2500948DC0 /* Helper.swift */; };
21 | 0E5112D71CCC6C2500948DC0 /* Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E5112D41CCC6C2500948DC0 /* Search.swift */; };
22 | 0E5112D81CCC6C2500948DC0 /* ThirtyDaysOfCodeChallenges.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E5112D51CCC6C2500948DC0 /* ThirtyDaysOfCodeChallenges.swift */; };
23 | 0E54009D1D5419340095128B /* LeetCodeKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E54009C1D5419340095128B /* LeetCodeKit.swift */; };
24 | 0E55254E1CD525A000942AD2 /* missnumberinput.txt in Resources */ = {isa = PBXBuildFile; fileRef = 0E55254D1CD525A000942AD2 /* missnumberinput.txt */; };
25 | 0E5525501CD5280800942AD2 /* misstest1.txt in Resources */ = {isa = PBXBuildFile; fileRef = 0E55254F1CD5280800942AD2 /* misstest1.txt */; };
26 | 0E57418B1C001FAF004EB0FA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E57418A1C001FAF004EB0FA /* AppDelegate.swift */; };
27 | 0E57418D1C001FAF004EB0FA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E57418C1C001FAF004EB0FA /* ViewController.swift */; };
28 | 0E5741901C001FAF004EB0FA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E57418E1C001FAF004EB0FA /* Main.storyboard */; };
29 | 0E5741921C001FAF004EB0FA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E5741911C001FAF004EB0FA /* Assets.xcassets */; };
30 | 0E5741951C001FAF004EB0FA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E5741931C001FAF004EB0FA /* LaunchScreen.storyboard */; };
31 | 0E5741A01C001FAF004EB0FA /* HRSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E57419F1C001FAF004EB0FA /* HRSwiftTests.swift */; };
32 | 0E5741AB1C001FAF004EB0FA /* HRSwiftUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E5741AA1C001FAF004EB0FA /* HRSwiftUITests.swift */; };
33 | 0E6F18021CCCA49F00FDE043 /* input10.txt in Resources */ = {isa = PBXBuildFile; fileRef = 0E6F18001CCCA49F00FDE043 /* input10.txt */; };
34 | 0E6F18031CCCA49F00FDE043 /* output10.txt in Resources */ = {isa = PBXBuildFile; fileRef = 0E6F18011CCCA49F00FDE043 /* output10.txt */; };
35 | 0E6FAD471D577DB800C8D71D /* 205_IsomorphicString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6FAD461D577DB800C8D71D /* 205_IsomorphicString.swift */; };
36 | 0E91413F1D5596D600C4CEFC /* 110_BalancedBinaryTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E91413E1D5596D600C4CEFC /* 110_BalancedBinaryTree.swift */; };
37 | 0E9141411D56213D00C4CEFC /* 112_PathSum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9141401D56213D00C4CEFC /* 112_PathSum.swift */; };
38 | 0E9141431D56372400C4CEFC /* 101_SymmetricTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9141421D56372400C4CEFC /* 101_SymmetricTree.swift */; };
39 | 0E9AC3521C65B0B0001DE1B6 /* GoogleInterviewQuestions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9AC3511C65B0B0001DE1B6 /* GoogleInterviewQuestions.swift */; };
40 | 0ED7FD561D52C51300EF082B /* 111_MinimumDepthOfBinaryTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED7FD551D52C51300EF082B /* 111_MinimumDepthOfBinaryTree.swift */; };
41 | 0ED7FD581D52E41400EF082B /* 104_MaximumDepthOfBinaryTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED7FD571D52E41400EF082B /* 104_MaximumDepthOfBinaryTree.swift */; };
42 | 0EE20BA21D51910500455550 /* 100_SameTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE20BA11D51910500455550 /* 100_SameTree.swift */; };
43 | 0EE20BA41D51AA5800455550 /* 226_InvertBinaryTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE20BA31D51AA5800455550 /* 226_InvertBinaryTree.swift */; };
44 | 0EEDD4C41C3F635A00F94031 /* DynamicProgramming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEDD4BE1C3F635A00F94031 /* DynamicProgramming.swift */; };
45 | 0EEDD4C51C3F635A00F94031 /* HackerRankKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEDD4BF1C3F635A00F94031 /* HackerRankKit.swift */; };
46 | 0EEDD4C61C3F635A00F94031 /* Implementation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEDD4C01C3F635A00F94031 /* Implementation.swift */; };
47 | 0EEDD4C71C3F635A00F94031 /* IndeedPrime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEDD4C11C3F635A00F94031 /* IndeedPrime.swift */; };
48 | 0EEDD4C81C3F635A00F94031 /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEDD4C21C3F635A00F94031 /* Strings.swift */; };
49 | 0EEDD4C91C3F635A00F94031 /* ZenefitsContest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEDD4C31C3F635A00F94031 /* ZenefitsContest.swift */; };
50 | /* End PBXBuildFile section */
51 |
52 | /* Begin PBXContainerItemProxy section */
53 | 0E57419C1C001FAF004EB0FA /* PBXContainerItemProxy */ = {
54 | isa = PBXContainerItemProxy;
55 | containerPortal = 0E57417F1C001FAF004EB0FA /* Project object */;
56 | proxyType = 1;
57 | remoteGlobalIDString = 0E5741861C001FAF004EB0FA;
58 | remoteInfo = HRSwift;
59 | };
60 | 0E5741A71C001FAF004EB0FA /* PBXContainerItemProxy */ = {
61 | isa = PBXContainerItemProxy;
62 | containerPortal = 0E57417F1C001FAF004EB0FA /* Project object */;
63 | proxyType = 1;
64 | remoteGlobalIDString = 0E5741861C001FAF004EB0FA;
65 | remoteInfo = HRSwift;
66 | };
67 | /* End PBXContainerItemProxy section */
68 |
69 | /* Begin PBXFileReference section */
70 | 0E2C0C931D565C9700748BAF /* 105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift; sourceTree = ""; };
71 | 0E2C0C951D56714500748BAF /* 106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift; sourceTree = ""; };
72 | 0E2C0C971D5680B800748BAF /* 113_PathSumII.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 113_PathSumII.swift; sourceTree = ""; };
73 | 0E2C0C991D56973300748BAF /* 98_ValidateBinarySearchTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 98_ValidateBinarySearchTree.swift; sourceTree = ""; };
74 | 0E2C0C9C1D56A18700748BAF /* 290_WordPattern.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 290_WordPattern.swift; sourceTree = ""; };
75 | 0E2C0C9E1D56E4F900748BAF /* 344_ReverseString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 344_ReverseString.swift; sourceTree = ""; };
76 | 0E2C0CA01D56E9A700748BAF /* 345_ReverseVowelsOfAString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 345_ReverseVowelsOfAString.swift; sourceTree = ""; };
77 | 0E2DFC351C604E9200644A7B /* Int+HRSwift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Int+HRSwift.swift"; path = "Sources/Int+HRSwift.swift"; sourceTree = ""; };
78 | 0E3C7E371D542BB200D6550A /* 337_HouseRobberIII.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 337_HouseRobberIII.swift; sourceTree = ""; };
79 | 0E3C7E391D54431100D6550A /* 102_BinaryTreeLevelOrderTraversal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 102_BinaryTreeLevelOrderTraversal.swift; sourceTree = ""; };
80 | 0E5112D31CCC6C2500948DC0 /* Helper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Helper.swift; path = Sources/Helper.swift; sourceTree = ""; };
81 | 0E5112D41CCC6C2500948DC0 /* Search.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Search.swift; path = Sources/Search.swift; sourceTree = ""; };
82 | 0E5112D51CCC6C2500948DC0 /* ThirtyDaysOfCodeChallenges.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ThirtyDaysOfCodeChallenges.swift; path = Sources/ThirtyDaysOfCodeChallenges.swift; sourceTree = ""; };
83 | 0E54009C1D5419340095128B /* LeetCodeKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeetCodeKit.swift; sourceTree = ""; };
84 | 0E55254D1CD525A000942AD2 /* missnumberinput.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = missnumberinput.txt; sourceTree = ""; };
85 | 0E55254F1CD5280800942AD2 /* misstest1.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = misstest1.txt; sourceTree = ""; };
86 | 0E5741871C001FAF004EB0FA /* HRSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HRSwift.app; sourceTree = BUILT_PRODUCTS_DIR; };
87 | 0E57418A1C001FAF004EB0FA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
88 | 0E57418C1C001FAF004EB0FA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
89 | 0E57418F1C001FAF004EB0FA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
90 | 0E5741911C001FAF004EB0FA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
91 | 0E5741941C001FAF004EB0FA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
92 | 0E5741961C001FAF004EB0FA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
93 | 0E57419B1C001FAF004EB0FA /* HRSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HRSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
94 | 0E57419F1C001FAF004EB0FA /* HRSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HRSwiftTests.swift; sourceTree = ""; };
95 | 0E5741A11C001FAF004EB0FA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
96 | 0E5741A61C001FAF004EB0FA /* HRSwiftUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HRSwiftUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
97 | 0E5741AA1C001FAF004EB0FA /* HRSwiftUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HRSwiftUITests.swift; sourceTree = ""; };
98 | 0E5741AC1C001FAF004EB0FA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
99 | 0E6F18001CCCA49F00FDE043 /* input10.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = input10.txt; sourceTree = ""; };
100 | 0E6F18011CCCA49F00FDE043 /* output10.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = output10.txt; sourceTree = ""; };
101 | 0E6FAD461D577DB800C8D71D /* 205_IsomorphicString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 205_IsomorphicString.swift; sourceTree = ""; };
102 | 0E91413E1D5596D600C4CEFC /* 110_BalancedBinaryTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 110_BalancedBinaryTree.swift; sourceTree = ""; };
103 | 0E9141401D56213D00C4CEFC /* 112_PathSum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 112_PathSum.swift; sourceTree = ""; };
104 | 0E9141421D56372400C4CEFC /* 101_SymmetricTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 101_SymmetricTree.swift; sourceTree = ""; };
105 | 0E9AC3511C65B0B0001DE1B6 /* GoogleInterviewQuestions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GoogleInterviewQuestions.swift; sourceTree = ""; };
106 | 0ED7FD551D52C51300EF082B /* 111_MinimumDepthOfBinaryTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 111_MinimumDepthOfBinaryTree.swift; sourceTree = ""; };
107 | 0ED7FD571D52E41400EF082B /* 104_MaximumDepthOfBinaryTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 104_MaximumDepthOfBinaryTree.swift; sourceTree = ""; };
108 | 0EE20BA11D51910500455550 /* 100_SameTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 100_SameTree.swift; sourceTree = ""; };
109 | 0EE20BA31D51AA5800455550 /* 226_InvertBinaryTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 226_InvertBinaryTree.swift; sourceTree = ""; };
110 | 0EEDD4BE1C3F635A00F94031 /* DynamicProgramming.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DynamicProgramming.swift; path = Sources/DynamicProgramming.swift; sourceTree = ""; };
111 | 0EEDD4BF1C3F635A00F94031 /* HackerRankKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HackerRankKit.swift; path = Sources/HackerRankKit.swift; sourceTree = ""; };
112 | 0EEDD4C01C3F635A00F94031 /* Implementation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Implementation.swift; path = Sources/Implementation.swift; sourceTree = ""; };
113 | 0EEDD4C11C3F635A00F94031 /* IndeedPrime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = IndeedPrime.swift; path = Sources/IndeedPrime.swift; sourceTree = ""; };
114 | 0EEDD4C21C3F635A00F94031 /* Strings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Strings.swift; path = Sources/Strings.swift; sourceTree = ""; };
115 | 0EEDD4C31C3F635A00F94031 /* ZenefitsContest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ZenefitsContest.swift; path = Sources/ZenefitsContest.swift; sourceTree = ""; };
116 | /* End PBXFileReference section */
117 |
118 | /* Begin PBXFrameworksBuildPhase section */
119 | 0E5741841C001FAF004EB0FA /* Frameworks */ = {
120 | isa = PBXFrameworksBuildPhase;
121 | buildActionMask = 2147483647;
122 | files = (
123 | );
124 | runOnlyForDeploymentPostprocessing = 0;
125 | };
126 | 0E5741981C001FAF004EB0FA /* Frameworks */ = {
127 | isa = PBXFrameworksBuildPhase;
128 | buildActionMask = 2147483647;
129 | files = (
130 | );
131 | runOnlyForDeploymentPostprocessing = 0;
132 | };
133 | 0E5741A31C001FAF004EB0FA /* Frameworks */ = {
134 | isa = PBXFrameworksBuildPhase;
135 | buildActionMask = 2147483647;
136 | files = (
137 | );
138 | runOnlyForDeploymentPostprocessing = 0;
139 | };
140 | /* End PBXFrameworksBuildPhase section */
141 |
142 | /* Begin PBXGroup section */
143 | 0E2C0C9B1D56A15E00748BAF /* String */ = {
144 | isa = PBXGroup;
145 | children = (
146 | 0E2C0C9C1D56A18700748BAF /* 290_WordPattern.swift */,
147 | 0E2C0C9E1D56E4F900748BAF /* 344_ReverseString.swift */,
148 | 0E2C0CA01D56E9A700748BAF /* 345_ReverseVowelsOfAString.swift */,
149 | 0E6FAD461D577DB800C8D71D /* 205_IsomorphicString.swift */,
150 | );
151 | path = String;
152 | sourceTree = "";
153 | };
154 | 0E57417E1C001FAF004EB0FA = {
155 | isa = PBXGroup;
156 | children = (
157 | 0EEDD4BD1C3F634500F94031 /* Sources */,
158 | 0E5741891C001FAF004EB0FA /* HRSwift */,
159 | 0E57419E1C001FAF004EB0FA /* HRSwiftTests */,
160 | 0E5741A91C001FAF004EB0FA /* HRSwiftUITests */,
161 | 0E5741881C001FAF004EB0FA /* Products */,
162 | );
163 | sourceTree = "";
164 | };
165 | 0E5741881C001FAF004EB0FA /* Products */ = {
166 | isa = PBXGroup;
167 | children = (
168 | 0E5741871C001FAF004EB0FA /* HRSwift.app */,
169 | 0E57419B1C001FAF004EB0FA /* HRSwiftTests.xctest */,
170 | 0E5741A61C001FAF004EB0FA /* HRSwiftUITests.xctest */,
171 | );
172 | name = Products;
173 | sourceTree = "";
174 | };
175 | 0E5741891C001FAF004EB0FA /* HRSwift */ = {
176 | isa = PBXGroup;
177 | children = (
178 | 0E6F17FE1CCCA49F00FDE043 /* TestFile */,
179 | 0E57418A1C001FAF004EB0FA /* AppDelegate.swift */,
180 | 0E57418C1C001FAF004EB0FA /* ViewController.swift */,
181 | 0E9AC3511C65B0B0001DE1B6 /* GoogleInterviewQuestions.swift */,
182 | 0E57418E1C001FAF004EB0FA /* Main.storyboard */,
183 | 0E5741911C001FAF004EB0FA /* Assets.xcassets */,
184 | 0E5741931C001FAF004EB0FA /* LaunchScreen.storyboard */,
185 | 0E5741961C001FAF004EB0FA /* Info.plist */,
186 | );
187 | path = HRSwift;
188 | sourceTree = "";
189 | };
190 | 0E57419E1C001FAF004EB0FA /* HRSwiftTests */ = {
191 | isa = PBXGroup;
192 | children = (
193 | 0E57419F1C001FAF004EB0FA /* HRSwiftTests.swift */,
194 | 0E5741A11C001FAF004EB0FA /* Info.plist */,
195 | );
196 | path = HRSwiftTests;
197 | sourceTree = "";
198 | };
199 | 0E5741A91C001FAF004EB0FA /* HRSwiftUITests */ = {
200 | isa = PBXGroup;
201 | children = (
202 | 0E5741AA1C001FAF004EB0FA /* HRSwiftUITests.swift */,
203 | 0E5741AC1C001FAF004EB0FA /* Info.plist */,
204 | );
205 | path = HRSwiftUITests;
206 | sourceTree = "";
207 | };
208 | 0E6F17FE1CCCA49F00FDE043 /* TestFile */ = {
209 | isa = PBXGroup;
210 | children = (
211 | 0E6F17FF1CCCA49F00FDE043 /* MaximiseSum */,
212 | );
213 | path = TestFile;
214 | sourceTree = "";
215 | };
216 | 0E6F17FF1CCCA49F00FDE043 /* MaximiseSum */ = {
217 | isa = PBXGroup;
218 | children = (
219 | 0E55254D1CD525A000942AD2 /* missnumberinput.txt */,
220 | 0E55254F1CD5280800942AD2 /* misstest1.txt */,
221 | 0E6F18001CCCA49F00FDE043 /* input10.txt */,
222 | 0E6F18011CCCA49F00FDE043 /* output10.txt */,
223 | );
224 | path = MaximiseSum;
225 | sourceTree = "";
226 | };
227 | 0EE20B9F1D51908A00455550 /* Leetcode */ = {
228 | isa = PBXGroup;
229 | children = (
230 | 0E54009C1D5419340095128B /* LeetCodeKit.swift */,
231 | 0E2C0C9B1D56A15E00748BAF /* String */,
232 | 0EE20BA01D5190AD00455550 /* Tree */,
233 | );
234 | name = Leetcode;
235 | path = Sources/Leetcode;
236 | sourceTree = "";
237 | };
238 | 0EE20BA01D5190AD00455550 /* Tree */ = {
239 | isa = PBXGroup;
240 | children = (
241 | 0E2C0C991D56973300748BAF /* 98_ValidateBinarySearchTree.swift */,
242 | 0EE20BA11D51910500455550 /* 100_SameTree.swift */,
243 | 0E9141421D56372400C4CEFC /* 101_SymmetricTree.swift */,
244 | 0E3C7E391D54431100D6550A /* 102_BinaryTreeLevelOrderTraversal.swift */,
245 | 0ED7FD571D52E41400EF082B /* 104_MaximumDepthOfBinaryTree.swift */,
246 | 0E2C0C931D565C9700748BAF /* 105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift */,
247 | 0E2C0C951D56714500748BAF /* 106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift */,
248 | 0E91413E1D5596D600C4CEFC /* 110_BalancedBinaryTree.swift */,
249 | 0ED7FD551D52C51300EF082B /* 111_MinimumDepthOfBinaryTree.swift */,
250 | 0E9141401D56213D00C4CEFC /* 112_PathSum.swift */,
251 | 0E2C0C971D5680B800748BAF /* 113_PathSumII.swift */,
252 | 0EE20BA31D51AA5800455550 /* 226_InvertBinaryTree.swift */,
253 | 0E3C7E371D542BB200D6550A /* 337_HouseRobberIII.swift */,
254 | );
255 | path = Tree;
256 | sourceTree = "";
257 | };
258 | 0EEDD4BD1C3F634500F94031 /* Sources */ = {
259 | isa = PBXGroup;
260 | children = (
261 | 0EE20B9F1D51908A00455550 /* Leetcode */,
262 | 0E5112D31CCC6C2500948DC0 /* Helper.swift */,
263 | 0E5112D41CCC6C2500948DC0 /* Search.swift */,
264 | 0E5112D51CCC6C2500948DC0 /* ThirtyDaysOfCodeChallenges.swift */,
265 | 0EEDD4BE1C3F635A00F94031 /* DynamicProgramming.swift */,
266 | 0EEDD4BF1C3F635A00F94031 /* HackerRankKit.swift */,
267 | 0EEDD4C01C3F635A00F94031 /* Implementation.swift */,
268 | 0EEDD4C11C3F635A00F94031 /* IndeedPrime.swift */,
269 | 0EEDD4C21C3F635A00F94031 /* Strings.swift */,
270 | 0EEDD4C31C3F635A00F94031 /* ZenefitsContest.swift */,
271 | 0E2DFC351C604E9200644A7B /* Int+HRSwift.swift */,
272 | );
273 | name = Sources;
274 | sourceTree = "";
275 | };
276 | /* End PBXGroup section */
277 |
278 | /* Begin PBXNativeTarget section */
279 | 0E5741861C001FAF004EB0FA /* HRSwift */ = {
280 | isa = PBXNativeTarget;
281 | buildConfigurationList = 0E5741AF1C001FAF004EB0FA /* Build configuration list for PBXNativeTarget "HRSwift" */;
282 | buildPhases = (
283 | 0E5741831C001FAF004EB0FA /* Sources */,
284 | 0E5741841C001FAF004EB0FA /* Frameworks */,
285 | 0E5741851C001FAF004EB0FA /* Resources */,
286 | );
287 | buildRules = (
288 | );
289 | dependencies = (
290 | );
291 | name = HRSwift;
292 | productName = HRSwift;
293 | productReference = 0E5741871C001FAF004EB0FA /* HRSwift.app */;
294 | productType = "com.apple.product-type.application";
295 | };
296 | 0E57419A1C001FAF004EB0FA /* HRSwiftTests */ = {
297 | isa = PBXNativeTarget;
298 | buildConfigurationList = 0E5741B21C001FAF004EB0FA /* Build configuration list for PBXNativeTarget "HRSwiftTests" */;
299 | buildPhases = (
300 | 0E5741971C001FAF004EB0FA /* Sources */,
301 | 0E5741981C001FAF004EB0FA /* Frameworks */,
302 | 0E5741991C001FAF004EB0FA /* Resources */,
303 | );
304 | buildRules = (
305 | );
306 | dependencies = (
307 | 0E57419D1C001FAF004EB0FA /* PBXTargetDependency */,
308 | );
309 | name = HRSwiftTests;
310 | productName = HRSwiftTests;
311 | productReference = 0E57419B1C001FAF004EB0FA /* HRSwiftTests.xctest */;
312 | productType = "com.apple.product-type.bundle.unit-test";
313 | };
314 | 0E5741A51C001FAF004EB0FA /* HRSwiftUITests */ = {
315 | isa = PBXNativeTarget;
316 | buildConfigurationList = 0E5741B51C001FAF004EB0FA /* Build configuration list for PBXNativeTarget "HRSwiftUITests" */;
317 | buildPhases = (
318 | 0E5741A21C001FAF004EB0FA /* Sources */,
319 | 0E5741A31C001FAF004EB0FA /* Frameworks */,
320 | 0E5741A41C001FAF004EB0FA /* Resources */,
321 | );
322 | buildRules = (
323 | );
324 | dependencies = (
325 | 0E5741A81C001FAF004EB0FA /* PBXTargetDependency */,
326 | );
327 | name = HRSwiftUITests;
328 | productName = HRSwiftUITests;
329 | productReference = 0E5741A61C001FAF004EB0FA /* HRSwiftUITests.xctest */;
330 | productType = "com.apple.product-type.bundle.ui-testing";
331 | };
332 | /* End PBXNativeTarget section */
333 |
334 | /* Begin PBXProject section */
335 | 0E57417F1C001FAF004EB0FA /* Project object */ = {
336 | isa = PBXProject;
337 | attributes = {
338 | LastSwiftUpdateCheck = 0710;
339 | LastUpgradeCheck = 0710;
340 | ORGANIZATIONNAME = "yansong li";
341 | TargetAttributes = {
342 | 0E5741861C001FAF004EB0FA = {
343 | CreatedOnToolsVersion = 7.1;
344 | };
345 | 0E57419A1C001FAF004EB0FA = {
346 | CreatedOnToolsVersion = 7.1;
347 | TestTargetID = 0E5741861C001FAF004EB0FA;
348 | };
349 | 0E5741A51C001FAF004EB0FA = {
350 | CreatedOnToolsVersion = 7.1;
351 | TestTargetID = 0E5741861C001FAF004EB0FA;
352 | };
353 | };
354 | };
355 | buildConfigurationList = 0E5741821C001FAF004EB0FA /* Build configuration list for PBXProject "HRSwift" */;
356 | compatibilityVersion = "Xcode 3.2";
357 | developmentRegion = English;
358 | hasScannedForEncodings = 0;
359 | knownRegions = (
360 | en,
361 | Base,
362 | );
363 | mainGroup = 0E57417E1C001FAF004EB0FA;
364 | productRefGroup = 0E5741881C001FAF004EB0FA /* Products */;
365 | projectDirPath = "";
366 | projectRoot = "";
367 | targets = (
368 | 0E5741861C001FAF004EB0FA /* HRSwift */,
369 | 0E57419A1C001FAF004EB0FA /* HRSwiftTests */,
370 | 0E5741A51C001FAF004EB0FA /* HRSwiftUITests */,
371 | );
372 | };
373 | /* End PBXProject section */
374 |
375 | /* Begin PBXResourcesBuildPhase section */
376 | 0E5741851C001FAF004EB0FA /* Resources */ = {
377 | isa = PBXResourcesBuildPhase;
378 | buildActionMask = 2147483647;
379 | files = (
380 | 0E5741951C001FAF004EB0FA /* LaunchScreen.storyboard in Resources */,
381 | 0E5741921C001FAF004EB0FA /* Assets.xcassets in Resources */,
382 | 0E55254E1CD525A000942AD2 /* missnumberinput.txt in Resources */,
383 | 0E6F18021CCCA49F00FDE043 /* input10.txt in Resources */,
384 | 0E6F18031CCCA49F00FDE043 /* output10.txt in Resources */,
385 | 0E5525501CD5280800942AD2 /* misstest1.txt in Resources */,
386 | 0E5741901C001FAF004EB0FA /* Main.storyboard in Resources */,
387 | );
388 | runOnlyForDeploymentPostprocessing = 0;
389 | };
390 | 0E5741991C001FAF004EB0FA /* Resources */ = {
391 | isa = PBXResourcesBuildPhase;
392 | buildActionMask = 2147483647;
393 | files = (
394 | );
395 | runOnlyForDeploymentPostprocessing = 0;
396 | };
397 | 0E5741A41C001FAF004EB0FA /* Resources */ = {
398 | isa = PBXResourcesBuildPhase;
399 | buildActionMask = 2147483647;
400 | files = (
401 | );
402 | runOnlyForDeploymentPostprocessing = 0;
403 | };
404 | /* End PBXResourcesBuildPhase section */
405 |
406 | /* Begin PBXSourcesBuildPhase section */
407 | 0E5741831C001FAF004EB0FA /* Sources */ = {
408 | isa = PBXSourcesBuildPhase;
409 | buildActionMask = 2147483647;
410 | files = (
411 | 0E91413F1D5596D600C4CEFC /* 110_BalancedBinaryTree.swift in Sources */,
412 | 0E5112D61CCC6C2500948DC0 /* Helper.swift in Sources */,
413 | 0EEDD4C91C3F635A00F94031 /* ZenefitsContest.swift in Sources */,
414 | 0ED7FD561D52C51300EF082B /* 111_MinimumDepthOfBinaryTree.swift in Sources */,
415 | 0EEDD4C71C3F635A00F94031 /* IndeedPrime.swift in Sources */,
416 | 0E2C0C9F1D56E4F900748BAF /* 344_ReverseString.swift in Sources */,
417 | 0EE20BA41D51AA5800455550 /* 226_InvertBinaryTree.swift in Sources */,
418 | 0EEDD4C61C3F635A00F94031 /* Implementation.swift in Sources */,
419 | 0E2C0CA11D56E9A700748BAF /* 345_ReverseVowelsOfAString.swift in Sources */,
420 | 0E3C7E381D542BB200D6550A /* 337_HouseRobberIII.swift in Sources */,
421 | 0ED7FD581D52E41400EF082B /* 104_MaximumDepthOfBinaryTree.swift in Sources */,
422 | 0E2C0C9A1D56973300748BAF /* 98_ValidateBinarySearchTree.swift in Sources */,
423 | 0E5112D81CCC6C2500948DC0 /* ThirtyDaysOfCodeChallenges.swift in Sources */,
424 | 0E57418D1C001FAF004EB0FA /* ViewController.swift in Sources */,
425 | 0E9141411D56213D00C4CEFC /* 112_PathSum.swift in Sources */,
426 | 0EEDD4C41C3F635A00F94031 /* DynamicProgramming.swift in Sources */,
427 | 0E9141431D56372400C4CEFC /* 101_SymmetricTree.swift in Sources */,
428 | 0E6FAD471D577DB800C8D71D /* 205_IsomorphicString.swift in Sources */,
429 | 0E2C0C961D56714500748BAF /* 106_ConstructBinaryTreeFromInorderAndPostorderTraversal.swift in Sources */,
430 | 0EE20BA21D51910500455550 /* 100_SameTree.swift in Sources */,
431 | 0E2C0C981D5680B800748BAF /* 113_PathSumII.swift in Sources */,
432 | 0E2C0C941D565C9700748BAF /* 105_ConstructBinaryTreeFromPreorderAndInorderTraversal.swift in Sources */,
433 | 0E57418B1C001FAF004EB0FA /* AppDelegate.swift in Sources */,
434 | 0E2C0C9D1D56A18700748BAF /* 290_WordPattern.swift in Sources */,
435 | 0E3C7E3A1D54431100D6550A /* 102_BinaryTreeLevelOrderTraversal.swift in Sources */,
436 | 0EEDD4C51C3F635A00F94031 /* HackerRankKit.swift in Sources */,
437 | 0E54009D1D5419340095128B /* LeetCodeKit.swift in Sources */,
438 | 0E2DFC361C604E9200644A7B /* Int+HRSwift.swift in Sources */,
439 | 0E5112D71CCC6C2500948DC0 /* Search.swift in Sources */,
440 | 0E9AC3521C65B0B0001DE1B6 /* GoogleInterviewQuestions.swift in Sources */,
441 | 0EEDD4C81C3F635A00F94031 /* Strings.swift in Sources */,
442 | );
443 | runOnlyForDeploymentPostprocessing = 0;
444 | };
445 | 0E5741971C001FAF004EB0FA /* Sources */ = {
446 | isa = PBXSourcesBuildPhase;
447 | buildActionMask = 2147483647;
448 | files = (
449 | 0E5741A01C001FAF004EB0FA /* HRSwiftTests.swift in Sources */,
450 | );
451 | runOnlyForDeploymentPostprocessing = 0;
452 | };
453 | 0E5741A21C001FAF004EB0FA /* Sources */ = {
454 | isa = PBXSourcesBuildPhase;
455 | buildActionMask = 2147483647;
456 | files = (
457 | 0E5741AB1C001FAF004EB0FA /* HRSwiftUITests.swift in Sources */,
458 | );
459 | runOnlyForDeploymentPostprocessing = 0;
460 | };
461 | /* End PBXSourcesBuildPhase section */
462 |
463 | /* Begin PBXTargetDependency section */
464 | 0E57419D1C001FAF004EB0FA /* PBXTargetDependency */ = {
465 | isa = PBXTargetDependency;
466 | target = 0E5741861C001FAF004EB0FA /* HRSwift */;
467 | targetProxy = 0E57419C1C001FAF004EB0FA /* PBXContainerItemProxy */;
468 | };
469 | 0E5741A81C001FAF004EB0FA /* PBXTargetDependency */ = {
470 | isa = PBXTargetDependency;
471 | target = 0E5741861C001FAF004EB0FA /* HRSwift */;
472 | targetProxy = 0E5741A71C001FAF004EB0FA /* PBXContainerItemProxy */;
473 | };
474 | /* End PBXTargetDependency section */
475 |
476 | /* Begin PBXVariantGroup section */
477 | 0E57418E1C001FAF004EB0FA /* Main.storyboard */ = {
478 | isa = PBXVariantGroup;
479 | children = (
480 | 0E57418F1C001FAF004EB0FA /* Base */,
481 | );
482 | name = Main.storyboard;
483 | sourceTree = "";
484 | };
485 | 0E5741931C001FAF004EB0FA /* LaunchScreen.storyboard */ = {
486 | isa = PBXVariantGroup;
487 | children = (
488 | 0E5741941C001FAF004EB0FA /* Base */,
489 | );
490 | name = LaunchScreen.storyboard;
491 | sourceTree = "";
492 | };
493 | /* End PBXVariantGroup section */
494 |
495 | /* Begin XCBuildConfiguration section */
496 | 0E5741AD1C001FAF004EB0FA /* Debug */ = {
497 | isa = XCBuildConfiguration;
498 | buildSettings = {
499 | ALWAYS_SEARCH_USER_PATHS = NO;
500 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
501 | CLANG_CXX_LIBRARY = "libc++";
502 | CLANG_ENABLE_MODULES = YES;
503 | CLANG_ENABLE_OBJC_ARC = YES;
504 | CLANG_WARN_BOOL_CONVERSION = YES;
505 | CLANG_WARN_CONSTANT_CONVERSION = YES;
506 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
507 | CLANG_WARN_EMPTY_BODY = YES;
508 | CLANG_WARN_ENUM_CONVERSION = YES;
509 | CLANG_WARN_INT_CONVERSION = YES;
510 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
511 | CLANG_WARN_UNREACHABLE_CODE = YES;
512 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
513 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
514 | COPY_PHASE_STRIP = NO;
515 | DEBUG_INFORMATION_FORMAT = dwarf;
516 | ENABLE_STRICT_OBJC_MSGSEND = YES;
517 | ENABLE_TESTABILITY = YES;
518 | GCC_C_LANGUAGE_STANDARD = gnu99;
519 | GCC_DYNAMIC_NO_PIC = NO;
520 | GCC_NO_COMMON_BLOCKS = YES;
521 | GCC_OPTIMIZATION_LEVEL = 0;
522 | GCC_PREPROCESSOR_DEFINITIONS = (
523 | "DEBUG=1",
524 | "$(inherited)",
525 | );
526 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
527 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
528 | GCC_WARN_UNDECLARED_SELECTOR = YES;
529 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
530 | GCC_WARN_UNUSED_FUNCTION = YES;
531 | GCC_WARN_UNUSED_VARIABLE = YES;
532 | IPHONEOS_DEPLOYMENT_TARGET = 9.1;
533 | MTL_ENABLE_DEBUG_INFO = YES;
534 | ONLY_ACTIVE_ARCH = YES;
535 | SDKROOT = iphoneos;
536 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
537 | TARGETED_DEVICE_FAMILY = "1,2";
538 | };
539 | name = Debug;
540 | };
541 | 0E5741AE1C001FAF004EB0FA /* Release */ = {
542 | isa = XCBuildConfiguration;
543 | buildSettings = {
544 | ALWAYS_SEARCH_USER_PATHS = NO;
545 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
546 | CLANG_CXX_LIBRARY = "libc++";
547 | CLANG_ENABLE_MODULES = YES;
548 | CLANG_ENABLE_OBJC_ARC = YES;
549 | CLANG_WARN_BOOL_CONVERSION = YES;
550 | CLANG_WARN_CONSTANT_CONVERSION = YES;
551 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
552 | CLANG_WARN_EMPTY_BODY = YES;
553 | CLANG_WARN_ENUM_CONVERSION = YES;
554 | CLANG_WARN_INT_CONVERSION = YES;
555 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
556 | CLANG_WARN_UNREACHABLE_CODE = YES;
557 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
558 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
559 | COPY_PHASE_STRIP = NO;
560 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
561 | ENABLE_NS_ASSERTIONS = NO;
562 | ENABLE_STRICT_OBJC_MSGSEND = YES;
563 | GCC_C_LANGUAGE_STANDARD = gnu99;
564 | GCC_NO_COMMON_BLOCKS = YES;
565 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
566 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
567 | GCC_WARN_UNDECLARED_SELECTOR = YES;
568 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
569 | GCC_WARN_UNUSED_FUNCTION = YES;
570 | GCC_WARN_UNUSED_VARIABLE = YES;
571 | IPHONEOS_DEPLOYMENT_TARGET = 9.1;
572 | MTL_ENABLE_DEBUG_INFO = NO;
573 | SDKROOT = iphoneos;
574 | TARGETED_DEVICE_FAMILY = "1,2";
575 | VALIDATE_PRODUCT = YES;
576 | };
577 | name = Release;
578 | };
579 | 0E5741B01C001FAF004EB0FA /* Debug */ = {
580 | isa = XCBuildConfiguration;
581 | buildSettings = {
582 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
583 | INFOPLIST_FILE = HRSwift/Info.plist;
584 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
585 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
586 | PRODUCT_BUNDLE_IDENTIFIER = com.yansong.HRSwift;
587 | PRODUCT_NAME = "$(TARGET_NAME)";
588 | };
589 | name = Debug;
590 | };
591 | 0E5741B11C001FAF004EB0FA /* Release */ = {
592 | isa = XCBuildConfiguration;
593 | buildSettings = {
594 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
595 | INFOPLIST_FILE = HRSwift/Info.plist;
596 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
597 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
598 | PRODUCT_BUNDLE_IDENTIFIER = com.yansong.HRSwift;
599 | PRODUCT_NAME = "$(TARGET_NAME)";
600 | };
601 | name = Release;
602 | };
603 | 0E5741B31C001FAF004EB0FA /* Debug */ = {
604 | isa = XCBuildConfiguration;
605 | buildSettings = {
606 | BUNDLE_LOADER = "$(TEST_HOST)";
607 | INFOPLIST_FILE = HRSwiftTests/Info.plist;
608 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
609 | PRODUCT_BUNDLE_IDENTIFIER = com.yansong.HRSwiftTests;
610 | PRODUCT_NAME = "$(TARGET_NAME)";
611 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HRSwift.app/HRSwift";
612 | };
613 | name = Debug;
614 | };
615 | 0E5741B41C001FAF004EB0FA /* Release */ = {
616 | isa = XCBuildConfiguration;
617 | buildSettings = {
618 | BUNDLE_LOADER = "$(TEST_HOST)";
619 | INFOPLIST_FILE = HRSwiftTests/Info.plist;
620 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
621 | PRODUCT_BUNDLE_IDENTIFIER = com.yansong.HRSwiftTests;
622 | PRODUCT_NAME = "$(TARGET_NAME)";
623 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HRSwift.app/HRSwift";
624 | };
625 | name = Release;
626 | };
627 | 0E5741B61C001FAF004EB0FA /* Debug */ = {
628 | isa = XCBuildConfiguration;
629 | buildSettings = {
630 | INFOPLIST_FILE = HRSwiftUITests/Info.plist;
631 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
632 | PRODUCT_BUNDLE_IDENTIFIER = com.yansong.HRSwiftUITests;
633 | PRODUCT_NAME = "$(TARGET_NAME)";
634 | TEST_TARGET_NAME = HRSwift;
635 | USES_XCTRUNNER = YES;
636 | };
637 | name = Debug;
638 | };
639 | 0E5741B71C001FAF004EB0FA /* Release */ = {
640 | isa = XCBuildConfiguration;
641 | buildSettings = {
642 | INFOPLIST_FILE = HRSwiftUITests/Info.plist;
643 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
644 | PRODUCT_BUNDLE_IDENTIFIER = com.yansong.HRSwiftUITests;
645 | PRODUCT_NAME = "$(TARGET_NAME)";
646 | TEST_TARGET_NAME = HRSwift;
647 | USES_XCTRUNNER = YES;
648 | };
649 | name = Release;
650 | };
651 | /* End XCBuildConfiguration section */
652 |
653 | /* Begin XCConfigurationList section */
654 | 0E5741821C001FAF004EB0FA /* Build configuration list for PBXProject "HRSwift" */ = {
655 | isa = XCConfigurationList;
656 | buildConfigurations = (
657 | 0E5741AD1C001FAF004EB0FA /* Debug */,
658 | 0E5741AE1C001FAF004EB0FA /* Release */,
659 | );
660 | defaultConfigurationIsVisible = 0;
661 | defaultConfigurationName = Release;
662 | };
663 | 0E5741AF1C001FAF004EB0FA /* Build configuration list for PBXNativeTarget "HRSwift" */ = {
664 | isa = XCConfigurationList;
665 | buildConfigurations = (
666 | 0E5741B01C001FAF004EB0FA /* Debug */,
667 | 0E5741B11C001FAF004EB0FA /* Release */,
668 | );
669 | defaultConfigurationIsVisible = 0;
670 | defaultConfigurationName = Release;
671 | };
672 | 0E5741B21C001FAF004EB0FA /* Build configuration list for PBXNativeTarget "HRSwiftTests" */ = {
673 | isa = XCConfigurationList;
674 | buildConfigurations = (
675 | 0E5741B31C001FAF004EB0FA /* Debug */,
676 | 0E5741B41C001FAF004EB0FA /* Release */,
677 | );
678 | defaultConfigurationIsVisible = 0;
679 | defaultConfigurationName = Release;
680 | };
681 | 0E5741B51C001FAF004EB0FA /* Build configuration list for PBXNativeTarget "HRSwiftUITests" */ = {
682 | isa = XCConfigurationList;
683 | buildConfigurations = (
684 | 0E5741B61C001FAF004EB0FA /* Debug */,
685 | 0E5741B71C001FAF004EB0FA /* Release */,
686 | );
687 | defaultConfigurationIsVisible = 0;
688 | defaultConfigurationName = Release;
689 | };
690 | /* End XCConfigurationList section */
691 | };
692 | rootObject = 0E57417F1C001FAF004EB0FA /* Project object */;
693 | }
694 |
--------------------------------------------------------------------------------