LeetCode 1. Two Sum - Swift Solution

Problem https://leetcode.com/problems/two-sum/ Problem Summary Given an array of integers and a target, find the indices of two numbers that add up to the target. Return the indices in any order. Solution class Solution { func twoSum ( _ nums : [ Int ], _ target : Int ) -> [ Int ] { var answer : [ Int ] = [] var dictionary : [ Int : Int ] = [ : ] for index in 0 .. < nums . count { let diff = target - nums [ index ] if let storedIndex = dictionary [ diff ] { answer = [ storedIndex , index ] break } else { dictionary [ nums [ index ]] = index } } return answer } } This code implements the solution to the "two sum" problem. The function takes an array of integers and a target integer as inputs and returns the indices of two numbers in the array that add up to the target....

About Binance Coin (BNB) Coin

이미지
Introduction to Binance Coin Binance Coin (BNB) is a digital asset created by Binance, the world's largest cryptocurrency exchange. It was launched in July 2017 and initially built as an ERC-20 token on the Ethereum blockchain, with the primary purpose of providing users with discounted trading fees on the Binance exchange. However, in April 2019, Binance announced that BNB would migrate from the Ethereum blockchain to its own blockchain, the Binance Chain. With the migration, Binance Coin also gained its own smart contract functionality, allowing developers to build decentralized applications (dApps) on top of the Binance Chain using BNB. Binance Coin's Technical Features Binance Coin has several technical features that make it a popular and versatile cryptocurrency: Decentralization Binance Coin is built on the Binance Chain, which is a decentralized blockchain, meaning that no single entity controls it. Scarcity There are only 170 million Binance Coins in existence, and no m...

Copy On Write of Swift structs

Swift is a popular programming language that is widely used to build a wide range of applications. One of its key features is its ability to handle memory management efficiently, which is achieved through various mechanisms, one of which is Copy On Write. In Swift, structs are value types, which means that when you create a new instance of a struct, a new copy of its entire memory allocation is created. This is different from reference types, such as classes, where multiple variables can point to the same instance of an object. However, creating a new copy of a struct every time it is accessed can be inefficient, especially when dealing with large data structures. This is where Copy On Write comes in, as it optimizes memory usage by creating a new copy of the struct only when it needs to be modified. To understand how Copy On Write works in terms of memory addresses, let's consider an example of a struct that contains an array of integers: struct MyStruct { var array = [...

About Cardano(ADA) Coin

이미지
Introduction to Cardano Cardano is a blockchain platform that was created in 2017 by Input Output Hong Kong (IOHK), a research and development company founded by Charles Hoskinson, one of the co-founders of Ethereum. The platform aims to provide a more secure and sustainable blockchain infrastructure by utilizing a proof-of-stake consensus algorithm and a layered architecture. Cardano's native cryptocurrency is ADA, which is used to pay for transactions on the platform and to incentivize validators in the proof-of-stake consensus algorithm. In this article, we will dive deeper into the features and capabilities of the Cardano platform and its native cryptocurrency, ADA. Cardano's Proof-of-Stake Consensus Algorithm Unlike Bitcoin's proof-of-work consensus algorithm, which relies on miners to solve complex mathematical equations to validate transactions, Cardano uses a proof-of-stake consensus algorithm called Ouroboros. In Ouroboros, validators, also known as stake pool oper...

HTTP vs HTTPS: What's the Difference and Why Does it Matter?

 When you browse the internet, you may notice that some websites start with " https ://" while others start with " http ://". So, what's the difference between these two protocols, and why does it matter? HTTP (Hypertext Transfer Protocol) is the protocol that has been used to transmit data over the internet since the early days of the World Wide Web. It defines how data is transmitted between computers and is the foundation for many internet-based applications and services. However, `http`  has a major flaw: it does not encrypt data, which means that anyone who intercepts the data can read it. This makes it easy for hackers to steal sensitive information like passwords, credit card numbers, and other personal data. To address this problem, HTTPS (Hypertext Transfer Protocol Secure) was developed. ' https'  adds an additional layer of security by using encryption to protect data as it is transmitted over the internet. This means that even if someone in...

JSONEncoder, JSONDecoder, NSKeyedArchiver and NSKeyedUnarchiver in Swift

Introduction In Swift, there are several ways to convert an object into a format that can be stored or transmitted. Two commonly used classes in the Foundation framework are NSKeyedArchiver and JSONEncoder, and their counterparts NSKeyedUnarchiver and JSONDecoder. In this article, we will discuss the differences between these two pairs of classes and when to use them. NSKeyedArchiver and NSKeyedUnarchiver NSKeyedArchiver and NSKeyedUnarchiver are classes that allow you to convert Swift objects to and from binary format. They require custom classes to implement the NSCoding protocol, which defines two methods: encode(with:) and init(coder:). The encode(with:) method is called by NSKeyedArchiver to encode the object's properties, while the init(coder:) method is called by NSKeyedUnarchiver to decode the object's properties. NSKeyedArchiver works by serializing objects into a binary format that can be stored or transmitted. To use NSKeyedArchiver, you need to implement the NSCodin...

Understanding And Use CoreData in iOS

CoreData is a powerful framework provided by Apple for managing data in iOS applications. CoreData is an Object Relational Mapping (ORM) system, which means it maps data between the application's objects and the persistent storage system. In this article, we will study CoreData in detail, including its operating principle, coordinator, container, and context.  Operating Principle of CoreData CoreData provides a way for developers to manage the application's data, store it persistently, and retrieve it when needed. When using CoreData, the developer defines an object model that describes the structure of the data that will be stored. This model defines the entities (i.e., the data types), their attributes (i.e., the fields), and their relationships (i.e., how the entities are related to each other). When the application starts, CoreData loads the object model and creates a persistent store coordinator. This coordinator manages the connection between the application's object...