This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| var A = [4, 10, 14, 7, 9, 3, 2, 8, 1, 16] | |
| func left(_ i: Int) -> Int { | |
| return i * 2 + 1 | |
| } | |
| func right(_ i: Int) -> Int { | |
| return i * 2 + 1 + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension String { | |
| var ascii: Int { | |
| return Int(unicodeScalars.first!.value) | |
| } | |
| } | |
| extension Int { | |
| var toString: String { | |
| return String(UnicodeScalar(self)!) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| class Node { | |
| var parent: Node? | |
| var childrens: [Character:Node] = [:] | |
| var isWord: Bool = false | |
| var count: Int = 0 | |
| init(parent: Node?) { | |
| self.parent = parent | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| func binarySearch<T: Comparable>(_ A: [T], key: T, _low: Int = 0, _high: Int = 0) -> Int? { | |
| var low = _low | |
| var high = _high | |
| if _high == 0 { | |
| high = A.count | |
| } | |
| while low < high { | |
| let mid = low + (high - low) / 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| func gcd(_ p: Int, _ q: Int) -> Int { | |
| return q == 0 ? p : gcd(q, p % q) | |
| } | |
| func lcm(_ p: Int, _ q: Int) -> Int { | |
| return p / gcd(p, q) * q | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| let x = 20 | |
| print(x&(x-1)) // 오른쪽 비트 끄기 | |
| print(x|(x+1)) // 제일 오른쪽 0의 비트 켜기 | |
| print(x&(x+1)) // 뒤에 딸린 1들을 끄기 | |
| print(x|(x-1)) // 뒤에 딸린 0들을 켜기 | |
| print((~x)&(x+1)) // 제일 오른쪽 0만 켜고 다른 것 다 끄기 | |
| print((~x)|(x-1)) // 제일 오른쪽 1만 끄고 다른 것 다 켜기 | |
| print((~x)&(x-1)) // 뒤에 딸린 0들만 켜고 다른 것 다 끄기 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <deque> | |
| using namespace std; | |
| template <typename T> | |
| struct Board { | |
| int w; | |
| int h; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int gcd(int p, int q) { | |
| return q == 0 ? p : gcd(q, p % q); | |
| } | |
| int lcm(int p, int q) { | |
| return p / gcd(p, q) * q; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| struct node { | |
| int key; | |
| node *left; | |
| node *right; | |
| node *parent; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| struct node { | |
| int key; | |
| int size; | |
| node *left; | |
| node *right; | |