8000 Finished Add Binary. · lexrus/LeetCode.swift@a4439b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit a4439b4

Browse files
committed
Finished Add Binary.
1 parent 46f1639 commit a4439b4

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

LeetCode.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
D7803DC21B95F1FE000C9270 /* 104.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7803DC11B95F1FE000C9270 /* 104.swift */; settings = {ASSET_TAGS = (); }; };
1414
D783CC9B1B2AC9160087FFC1 /* 226.swift in Sources */ = {isa = PBXBuildFile; fileRef = D783CC9A1B2AC9160087FFC1 /* 226.swift */; };
1515
D7AB14CB1B99C85200DEDE9D /* 58.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AB14CA1B99C85200DEDE9D /* 58.swift */; settings = {ASSET_TAGS = (); }; };
16+
D7AB14CE1B9B34FA00DEDE9D /* 67.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AB14CD1B9B34FA00DEDE9D /* 67.swift */; settings = {ASSET_TAGS = (); }; };
1617
D7DE016B1AF9F13600BB2AA0 /* 100.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7DE016A1AF9F13600BB2AA0 /* 100.swift */; };
1718
D7FB8E161AF89A2700286272 /* 38.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7FB8E151AF89A2700286272 /* 38.swift */; };
1819
D7FB8E181AF89A3200286272 /* 28.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7FB8E171AF89A3200286272 /* 28.swift */; };
@@ -45,6 +46,8 @@
4546
D7803DC11B95F1FE000C9270 /* 104.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 104.swift; sourceTree = "<group>"; };
4647
D783CC9A1B2AC9160087FFC1 /* 226.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 226.swift; sourceTree = "<group>"; };
4748
D7AB14CA1B99C85200DEDE9D /* 58.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 58.swift; sourceTree = "<group>"; };
49+
D7AB14CC1B9B344900DEDE9D /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
50+
D7AB14CD1B9B34FA00DEDE9D /* 67.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 67.swift; sourceTree = "<group>"; };
4851
D7DE016A1AF9F13600BB2AA0 /* 100.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 100.swift; sourceTree = "<group>"; };
4952
D7FB8E091AF899FE00286272 /* LeetCodeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LeetCodeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5053
D7FB8E0C1AF899FE00286272 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -86,6 +89,7 @@
8689
D77C33131ADE363800D4843B = {
8790
isa = PBXGroup;
8891
children = (
92+
D7AB14CC1B9B344900DEDE9D /* README.md */,
8993
D7FB8E541AF89CCF00286272 /* Shared */,
9094
D7FB8E0A1AF899FE00286272 /* Tests */,
9195
D77C331D1ADE363800D4843B /* Products */,
@@ -121,6 +125,7 @@
121125
D7AB14CA1B99C85200DEDE9D /* 58.swift */,
122126
D7FB8E611AF8B33600286272 /* 65.swift */,
123127
D7FB8E651AF9B09100286272 /* 66.swift */,
128+
D7AB14CD1B9B34FA00DEDE9D /* 67.swift */,
124129
D7FB8E691AF9B9D400286272 /* 82.swift */,
125130
D7FB8E211AF89AA200286272 /* 88.swift */,
126131
D7DE016A1AF9F13600BB2AA0 /* 100.swift */,
@@ -228,6 +233,7 @@
228233
D7FB8E5C1AF8A6FE00286272 /* 21.swift in Sources */,
229234
D7FB8E201AF89A9700286272 /* 13.swift in Sources */,
230235
D7FB8E661AF9B09100286272 /* 66.swift in Sources */,
236+
D7AB14CE1B9B34FA00DEDE9D /* 67.swift in Sources */,
231237
D7AB14CB1B99C85200DEDE9D /* 58.swift in Sources */,
232238
D7FB8E161AF89A2700286272 /* 38.swift in Sources */,
233239
D7FB8E621AF8B33600286272 /* 65.swift in Sources */,

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Travis](https://img.shields.io/travis/lexrus/LeetCode.swift.svg)](https://travis-ci.org/lexrus/LeetCode.swift)
44
![Language](https://img.shields.io/badge/language-Swift%202-orange.svg)
55
![License](https://img.shields.io/github/license/lexrus/ios-dev-playbook.svg?style=flat)
6-
![Progress](https://img.shields.io/badge/Progress-25%20%2F%20257%20=%209.73%25-ff69b4.svg)
6+
![Progress](https://img.shields.io/badge/Progress-26%20%2F%20257%20=%2010.12%25-ff69b4.svg)
77

88
> 愚者千虑,必有一得。
99
@@ -81,7 +81,7 @@ let 😎 = Easy, 😐 = Medium, 😨 = Hard
8181
- [ ] 64 😐 [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum/) [.swift](./Tests/64.swift)
8282
- [x] 65 😨 [Valid Number](https://leetcode.com/problems/valid-number/) [.swift](./Tests/65.swift)
8383
- [x] 66 😎 [Plus One](https://leetcode.com/problems/plus-one/) [.swift](./Tests/66.swift)
84-
- [ ] 67 😎 [Add Binary](https://leetcode.com/problems/add-binary/) [.swift](./Tests/67.swift)
84+
- [x] 67 😎 [Add Binary](https://leetcode.com/problems/add-binary/) [.swift](./Tests/67.swift)
8585
- [ ] 68 😨 [Text Justification](https://leetcode.com/problems/text-justification/) [.swift](./Tests/68.swift)
8686
- [ ] 69 😐 [Sqrt(x)](https://leetcode.com/problems/sqrtx/) [.swift](./Tests/69.swift)
8787
- [ ] 70 😎 [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) [.swift](./Tests/70.swift)

Tests/67.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// 67.swift
3+
// LeetCode
4+
//
5+
// Created by Lex on 9/5/15.
6+
// Copyright © 2015 Lex Tang. All rights reserved.
7+
//
8+
9+
import XCTest
10+
11+
func addBinary(a: String, _ b: String) -> String {
12+
let ai = Int(a, radix: 2) ?? 0
13+
let bi = Int(b, radix: 2) ?? 0
14+
let result = ai + bi
15+
return String(result, radix: 2)
16+
}
17+
18+
class AddBinaryTest: XCTestCase {
19+
20+
func testExample() {
21+
XCTAssert(addBinary("11", "1") == "100")
22+
XCTAssert(addBinary("1111111", "222") == "1111111")
23+
XCTAssert(addBinary("", "1") == "1")
24+
XCTAssert(addBinary("0", "0") == "0")
25+
}
26+
27+
}

0 commit comments

Comments
 (0)
0