This file contains 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
# RESULT | |
node1 = SinglyLinkedListNode(1) | |
node2 = SinglyLinkedListNode(2) | |
node3 = SinglyLinkedListNode(3) | |
node1.next = node2 | |
node2.next = node3 | |
result = insertNodeAtTail(node1, 34) |
This file contains 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
from linked_list import SinglyLinkedListNode | |
def insertNodeAtTail(head, data): | |
if head is None: | |
return SinglyLinkedListNode(data) | |
else: | |
current_node = head | |
while current_node.next is not None: | |
current_node = current_node.next |
This file contains 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
# RESULT | |
node1 = SinglyLinkedListNode(1) | |
node2 = SinglyLinkedListNode(2) | |
node3 = SinglyLinkedListNode(3) | |
node1.next = node2 | |
node2.next = node3 | |
printLinkedList(node1) |
This file contains 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
from linked_list import SinglyLinkedListNode | |
def printLinkedList(head): | |
currentNode = head | |
while currentNode is not None: | |
print(currentNode.data) | |
currentNode = currentNode.next |
This file contains 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
"""Linked List Realization""" | |
class SinglyLinkedListNode: | |
def __init__(self, node_data): | |
self.data = node_data | |
self.next = None |
This file contains 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
func climbingLeaderboard(scores: [Int], alice: [Int]) -> [Int] { | |
func findClosestNumberInBoard(forNumber number: Int) -> Int { //Functions for searching the closest score in table | |
var left = 0 //with binary search | |
var right = scores.count - 1 | |
var mid = 0 | |
while left <= right { | |
mid = (left + right) / 2 | |
if number == scores[mid] { |
This file contains 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
func pickingNumbers(a: [Int]) -> Int { | |
var repeatList = Array(repeating: 0, count: 100) //Generated list with 100 zeros | |
for i in 0..<a.count { //Count repeating of each item in input array | |
repeatList[a[i] - 1] += 1 | |
} | |
var result = 0 | |
for i in 0..<(repeatList.count - 1) { | |
let stepSum = repeatList[i] + repeatList[i + 1] //Sum of each item and next item | |
if stepSum > result { //The biggest met sum is our answer | |
result = stepSum |
This file contains 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
let magic1 = [[8, 1, 6], [3, 5, 7], [4, 9, 2]] | |
let magic2 = [[6, 1, 8], [7, 5, 3], [2, 9, 4]] | |
let magic3 = [[4, 9, 2], [3, 5, 7], [8, 1, 6]] | |
let magic4 = [[2, 9, 4], [7, 5, 3], [6, 1, 8]] | |
let magic5 = [[8, 3, 4], [1, 5, 9], [6, 7, 2]] | |
let magic6 = [[4, 3, 8], [9, 5, 1], [2, 7, 6]] | |
let magic7 = [[6, 7, 2], [1, 5, 9], [8, 3, 4]] | |
let magic8 = [[2, 7, 6], [9, 5, 1], [4, 3, 8]] | |
let posibleMagicSquares = [magic1, magic2, magic3, magic4, magic5, magic6, magic7, magic8] | |
var allPosibleAnswers: [Int] = [] |
This file contains 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
/* | |
Sample Input | |
*/ | |
s = | |
4 9 2 | |
3 5 7 | |
8 1 5 | |
/* | |
Sample Output - 1 |
This file contains 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
private func getDrinkingTubeShape() -> CAShapeLayer { | |
//Wraper Shape | |
let wrapPath = UIBezierPath() | |
wrapPath.move(to: CGPoint(x: 170, y: 145)) | |
wrapPath.addLine(to: CGPoint(x: 125, y: 70)) | |
wrapPath.addLine(to: CGPoint(x: 5, y: 110)) | |
wrapPath.addQuadCurve(to: CGPoint(x: 35, y: 175), | |
controlPoint: CGPoint(x: -5, y: 160)) | |
wrapPath.addQuadCurve(to: CGPoint(x: 95, y: 150), | |
controlPoint: CGPoint(x: 60, y: 165)) |