Functions in Kotlin

In this post, I aim to summarize the essential aspects of function syntax in Kotlin. While this post touches upon some commonly used functionalities, especially in Android development, it doesn’t delve deep into the advanced usages. Regular Functions Regular functions are the basic building blocks. Here’s a simple function that compares the lengths of two strings: 1 2 3 fun compare(a: String, b: String): Boolean { return a.length < b.length

Three.js Fundamentals

This blog post is primarily intended to document my learning journey with three.js. At its core, this framework is a JavaScript library built on top of WebGL, designed to help developers efficiently create 3D models and scenes. Here are some fundamental concepts and code snippets: Primary Classes First, let’s take a glance at the structural diagram: Renderer As seen from the above structural diagram, right at the top is the

0-1 Knapsack Problem

Introduction to the 0-1 Knapsack Problem The 0-1 Knapsack problem is a classic optimization problem. Imagine you have a bag with a certain weight capacity, and you have a set of items, each with its own weight and value. The problem is to determine which items to include in the bag to maximize its total value without exceeding its weight capacity. Brute Force The simplest way to tackle the 0-1

Recursively Traverse a Binary Tree

Traversal Order A binary tree offers three primary traversal methods: Pre-order, In-order, and Post-order. 1 2 3 4 5 6 1 / \ 2 3 / \ \ 4 5 6 pre-order: 1->2->4->5->3->6 in-order: 4->2->5->1->3->6 post-prder: 4->5->2->6->3->1 The root node appears first in pre-order traversal and last in post-order traversal. Leveraging this characteristic, one can uniquely construct a binary tree when provided with combinations of preorder-inorder or postorder-inorder arrays. Note

坎昆之旅

多年之后再次来到墨西哥,莫名有点感动,当年离开的时候和当地的朋友一起吃饭,朋友说我们以后应该很难再见面了。 这次带老婆来墨国,最终还是选择了坎