-
WSL2 Network
How to access server which is hosted on WSL2 ? Use proxy to forward connection from win10 to wsl2. [powershell] > netsh interface portproxy show all # listen address/port -> windows 10 ip/port # connect address/port -> wsl2 ip/port [powershell] > netsh interface portproxy add v4tov4 listenaddress=0.0.0... Read More
-
[HTB - Starting Point] Three
Task 1 Q : How many TCP ports are open? [host] # nmap -sVC -p- --open <target_ip> -oA Three_full_scan A : 2 Task 2 Q : What is the domain of the email address provided in the “Contact” section of the website? A : thetoppers.htb Task 3 Q : In the absence of a DNS server, which Linux file can we use to resolve hostnames to IP addresses in... Read More
-
[HTB - Starting Point] Archetype
Task 1 Q : Which TCP port is hosting a database server? [host] # nmap -sVC -p- --open -oA Archetype_full_scan <target_ip> A : 1433 Task 2 Q : What is the name of the non-Administrative share available over SMB? [host] # smbclient -N -L <target_ip> A : backups Task 3 Q : What is the password identified in the file on the SMB share... Read More
-
[HTB - Starting Point] Sequel
Task 1 Q : What does the acronym SQL stand for? A : Structured Query Language Task 2 Q : During our scan, which port running mysql do we find? [host] # nmap -sVC --open -oA Sequel_init_scan <target_ip> A : 3306 Task 3 Q : What community-developed MySQL version is the target running? A : MariaDB Task 4 Q : What switch do we need to use ... Read More
-
[HTB - Starting Point] Responder
Task 1 Q : When visiting the web service using the IP address, what is the domain that we are being redirected to? A : unika.htb Note : In order to view the website, add unika.htb domain into hosts file. Task 2 Q : Which scripting language is being used on the server to generate webpages? A : PHP Note : Use wappalyzer Task 3 Q : What is the na... Read More
-
[HTB - Starting Point] Crocodile
Task 1 Q : What nmap scanning switch employs the use of default scripts during a scan? A : -sC Task 2 Q : What service version is found to be running on port 21? [host] # nmap -sCV --open -oA Crocodile_init_scan <target_ip> A : vsftpd 3.0.3 Task 3 Q : What FTP code is returned to us for the “Anonymous FTP login allowed” message? [host] ... Read More
-
[HTB - Starting Point] Appointment
Task 1 Q : What does the acronym SQL stand for? A : Structured Query Language Task 2 Q : What is one of the most common type of SQL vulnerabilities? A : sql injection Task 3 Q : What does PII stand for? A : personally identifiable information Task 4 Q : What does the OWASP Top 10 list name the classification for this vulnerability? A : A03:20... Read More
-
[HTB - Starting Point] Redeemer
Task 1 Q : Which TCP port is open on the machine? [host] # nmap --open -p- -sV <target_ip> -oA Redeemer_full_scan A : 6379 Task 2 Q : Which service is running on the port that is open on the machine? A : redis Task 3 Q : What type of database is Redis? Choose from the following options: (i) In-memory Database, (ii) Traditional Database ... Read More
-
[HTB - Starting Point] Fawn
Task 1 Q : What does the 3-letter acronym FTP stand for? A : File Transfer Protocol Task 2 Q : Which port does the FTP service listen on usually? A : 21 Task 3 Q : What acronym is used for the secure version of FTP? A : SFTP Task 4 Q : What is the command we can use to send an ICMP echo request to test our connection to the target? A : ping ... Read More
-
[HTB - Starting Point] Dancing
Task 1 Q : What does the 3-letter acronym SMB stand for? A : Server Message Block Task 2 Q : What port does SMB use to operate at? A : 445 Task 3 Q : What is the service name for port 445 that came up in our Nmap scan? [host] # nmap -sV --open <target_ip> -oA Dancing_init_scan A : microsoft-ds Task 4 Q : What is the ‘flag’ or ‘switch’ ... Read More
-
[HTB - Starting Point] Meow
Task 1 Q : What does the acronym VM stand for? A : Virtual Machine Task 2 Q : What tool do we use to interact with the operating system in order to issue commands via the command line, such as the one to start our VPN connection? It’s also known as a console or shell. A : Terminal Task 3 Q : What service do we use to form our VPN connection in... Read More
-
Linux Device Driver 3rd edition - CH5 recap
Concurrency and Race Conditions what is concurrency? what happens when the system tries to do more than one thing a once. concurrency is one of the core problems in operating system. concurrency-related bugs are some of the easiest to create and some of hardest to find. Pitfalls in scull // write logic if (!dp... Read More
-
sg3 utils
reference: The sg3_utils package Introduction Send SCSI commands to devices on transports traditionally associated with SCSI. Fibre Channel (FCP) Serial Attached SCSI (SAS) SCSI Parallel Interface (SPI) ATAPI cd/dvd drivers and SATA disks connect via a translation layer or a bridge that use SCSI command sets. ... Read More
-
Linux Device Driver 3rd edition - CH4 recap
Debugging Techniques Debugging Support in the Kernel Configuration options in kernel CONFIG_DEBUG_KERNEL Just make other debugging options available. CONFIG_DEBUG_SLAB Set allocated memory to 0xa5. Set freed memory to 0x6b. CONFIG_DEBUG_PAGE... Read More
-
Basic scull build from scratch
Flowchart scull.c #include <linux/init.h> /* essential */ #include <linux/module.h> /* essential */ #include <linux/fs.h> /* file system */ #include <linux/types.h> /* dev_t */ #include <linux/errno.h> /* error code */ #include <linux/cdev.h> /* char device */ #include <linux/slab.h> /* kmalloc, k... Read More
-
Linux Device Driver 3rd edition - CH3 recap
Char Drivers Take scull (Simple Character Utility for Loading Localities) for example. scull is not hardware dependent, it is a device which acts on some memory allocated from the kernel. scull is used to demonstrate the interface between the kernel and char drivers and allow the user to run some tests. The Design of scull The firs... Read More
-
Linux Device Driver 3rd edition - CH2 recap
Building and Running Modules Setting Up Your Test System You can get latest mainline kernel from kernel.org to setup your test environment. [Tip] Prepare a “sacrificial” environment to test your new code, so that it won’t ruin your machine. (The possibility of bugs is always present) The Hello World Module #include <linux/init.h> #inclu... Read More
-
oh-my-zsh Setup
Result (using Tabby terminal) Setup steps update OS $ sudo apt-get update $ sudo apt-get upgrade install zsh $ sudo apt-get install -y zsh // check zsh is installed. $ cat /etc/shells // change default shell $ chsh -s $(which zsh) install oh-my-zsh $ sh -c "$(wget -O- https://raw.githubusercontent.c... Read More
-
Linux Device Driver 3rd edition - CH1 recap
An Introduction to Device Drivers Role of Device driver Black boxes between user(applications) and hardware. Provide mechanism (what capabilities are to be provided) instead of policy(how those capabilities can be used) Splitting the Kernel Process management Memory management Filesystems Device control Networking Load... Read More
-
WSL git clone error
Git clone with Ubuntu WSL, and an error occured. error: chmod on /mnt/d/nshawn4675.github.io/.git/config.lock failed: Operation not permitted Because /mnt/d is a NTFS partition so that chmod doesn’t work. Steps to solve this problem: Launch Ubuntu WSL Create / Modify WSL conf file $ sudo vi /etc/wsl.conf [automount] opt... Read More
-
Enlarge swap space
Enlarge swap space to 16GB $ sudo swapoff /swapfile $ sudo rm /swapfile $ sudo dd if=/dev/zero of=/swapfile bs=1M count=16384 $ sudo chmod 600 /swapfile $ sudo mkswap /swapfile $ sudo swapon /swapfile // check swap $ cat /proc/swaps Read More
-
Windows10 & VirtualBox Ubuntu20.04 - shared folder
Add a shared folder on host side. virtualbox → your machine (powered off) → settings → Shared Folders → Add new shared folder → select “Folder Path” on win10 → enter “Folder Name” = “win10_shared” → unchecked “Read-only” and “Auto-mount”. Install VBoxLinuxAdditions on guest side. Turn on machine → Devices → Insert Guest Addtions CD Image… // ... Read More
-
[LeetCode April Challange] Day 21 - Triangle
Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row. Example 1: Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]] Output: 11 Explanation: T... Read More
-
[LeetCode April Challange] Day 20 - N-ary Tree Preorder Traversal
Given the root of an n-ary tree, return the preorder traversal of its nodes’ values. Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples) Example 1: Input: root = [1,null,3,2,4,null,5,6] Output: [1,3,5,6,2,4] Example 2: Input: root = [1,null,2,... Read More
-
[LeetCode April Challange] Day 18 - Remove Nth Node From End of List
Given the head of a linked list, remove the n-th node from the end of the list and return its head. Follow up: Could you do this in one pass? Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] Constraints: The number of no... Read More
-
[LeetCode April Challange] Day 15 - Fibonacci Number
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F(0) = 0, F(1) = 1 F(n) = F(n - 1) + F(n - 2), for n > 1. Given n, calculate F(n). Example 1: Input: n = 2 Output: 1 Explanation: F(2) = F(1) + F(0) = 1 +... Read More
-
[LeetCode April Challange] Day 14 - Partition List
Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. Example 1: Input: head = [1,4,3,2,5,2], x = 3 Output: [1,2,2,4,3,5] Example 2: Input: head = [2,1], x = 2 Out... Read More
-
[LeetCode April Challange] Day 13 - Flatten Nested List Iterator
You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it. Implement the NestedIterator class: NestedIterator(List<NestedInteger> nestedList) Initializes the iterator with the nested list nestedList. int next... Read More
-
[LeetCode April Challange] Day 12 - Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3, … , an], then the list [|a1 - a2|, |a2 - a3|, |a3 - a4|, … , |an-1 - an|] has exactly k distinct integers. If there are multiple answers, print any of th... Read More
-
[LeetCode April Challange] Day 11 - Deepest Leaves Sum
Given the root of a binary tree, return the sum of values of its deepest leaves. Example 1: Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8] Output: 15 Example 2: Input: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5] Output: 19 Constraints: The number of nodes in the tree is in the range [1, 10^4]. 1 <= Node.va... Read More
-
[LeetCode April Challange] Day 10 - Longest Increasing Path in a Matrix
Given an m x n</fotn> integers matrix, return *the length of the longest increasing path in* matrix. From each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or move outside the boundary (i.e., wrap-around is not allowed). Example 1: Input: matrix = [[9,9,4],[6,6,8],[2,1,1]] Output:... Read More
-
Inorder Successor in BST
Given the root of a binary search tree and a node p in it, return the in-order successor of that node in the BST. If the given node has no in-order successor in the tree, return null. The successor of a node p is the node with the smallest key greater than p.val. Example 1: Input: root = [2,1,3], p = 1 Output: 2 Explanation: 1's in-order su... Read More
-
[LeetCode April Challange] Day 09 - Verifying an Alien Dictionary
In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters. Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographicaly in this ... Read More
-
[LeetCode April Challange] Day 08 - Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1: Input: digits = "23" Output: ["ad","ae","af","bd"... Read More
-
Largest Unique Number
Given an array of integers A, return the largest integer that only occurs once. If no integer occurs once, return -1. Example 1: Input: [5,7,3,9,4,9,8,3,1] Output: 8 Explanation: The maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it's the answer. Example 2: Input: [9,9,8,8] Output: -1 Explanation: ... Read More
-
[LeetCode April Challange] Day 07 - Determine if String Halves Are Alike
You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half. Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters. Return true if a and b are al... Read More
-
[LeetCode April Challange] Day 06 - Minimum Operations to Make Array Equal
You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e. 0 <= i < n). In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e. perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array equal. It is gu... Read More
-
[LeetCode April Challange] Day 05 - Global and Local Inversions
We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) inversions is the number of i < j with 0 <= i < j < N and A[i] > A[j]. The number of local inversions is the number of i with 0 <= i < N and A[i] > A[i+1]. Return true if and only if the number of global inversions is e... Read More
-
[LeetCode April Challange] Day 04 - Design Circular Queue
Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called “Ring Buffer”. One of the benefits of the circular queue is that we c... Read More
-
[LeetCode April Challange] Day 03 - Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. Example 1: Input: s = "(()" Output: 2 Explanation: The longest valid parentheses substring is "()". Example 2: Input: s = ")()())" Output: 4 Explanation: The longest valid parentheses substring is "()()". Ex... Read More
-
[LeetCode April Challange] Day 02 - Ones and Zeroes
You are given an array of binary strings strs and two integers m and n. Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset. A set x is a subset of a set y if all elements of x are also elements of y. Example 1: Input: strs = ["10","0001","111001","1","0"], m = 5, n = 3 Output: 4 Explanatio... Read More
-
[LeetCode April Challange] Day 01 - Palindrome Linked List
Given the head of a singly linked list, return true if it is a palindrome. Example 1: Input: head = [1,2,2,1] Output: true Example 2: Input: head = [1,2] Output: false Constraints: The number of nodes in the list is in the range [1, 10^5]. 0 <= Node.val <= 9 Follow up: Could you do it in O(n) time and O(1) space?... Read More
-
[LeetCode March Challange] Day 10 - Integer to Roman
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one’s added together. 12 is written as XII, which is simply X ... Read More
-
[LeetCode March Challange] Day 09 - Add One Row to Tree
Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth. Note that the root node is at depth 1. The adding rule is: Given the integer depth, for each not null tree node cur at the depth depth - 1, create two tree nodes with value val as cur’s left subtree root and right sub... Read More
-
[LeetCode March Challange] Day 08 - Remove Palindromic Subsequences
Given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s. Return the minimum number of steps to make the given string empty. A string is a subsequence of a given string, if it is generated by deleting some characters of a given string without changing its order. A string is ca... Read More
-
[LeetCode March Challange] Day 07 - Design HashMap
Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: MyHashMap() initializes the object with an empty map. void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value. int get(int key) returns the value to whic... Read More
-
[LeetCode March Challange] Day 06 - Short Encoding of Words
A valid encoding of an array of words is any reference string s and array of indices indices such that: words.length == indices.length The reference string s ends with the '#' character. For each index indices[i], the substring of s starting from indices[i] and up to (but not including) the next '#' character is equal to words[i]... Read More
-
[LeetCode March Challange] Day 05 - Average of Levels in Binary Tree
Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10^-5 of the actual answer will be accepted. Example 1: Input: root = [3,9,20,null,15,7] Output: [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 i... Read More
-
[LeetCode March Challange] Day 04 - Intersection of Two Linked Lists
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null. For example, the following two linked lists begin to intersect at node c1: It is guaranteed that there are no cycles anywhere in the entire linked structure. Note tha... Read More
-
[LeetCode March Challange] Day 03 - Missing Number
Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity? Example 1: Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all... Read More
-
[LeetCode March Challange] Day 02 - Set Mismatch
You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number. You are given an integer array nums representing the data status of this set after the e... Read More
-
[LeetCode March Challange] Day 01 - Distribute Candies
Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor. The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still follo... Read More
-
[LeetCode February Challange] Day 28 - Maximum Frequency Stack
Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack. Implement the FreqStack class: FreqStack() constructs an empty frequency stack. void push(int val) pushes an integer val onto the top of the stack. int pop() removes and returns the most frequent element in the stack. ... Read More
-
[LeetCode February Challange] Day 27 - Divide Two Integers
Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 and truncate(-2.7335) = -2. Note: Assume w... Read More
-
[LeetCode February Challange] Day 26 - Validate Stack Sequences
Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack. Example 1: Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1] Output: true Explanation: We might do the following sequence: push(1), push(2), push(3), push(4... Read More
-
[LeetCode February Challange] Day 25 - Shortest Unsorted Continuous Subarray
Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order. Return the shortest such subarray and output its length. Example 1: Input: nums = [2,6,4,8,10,9,15] Output: 5 Explanation: You need to sort [6, 4, 8, 10, 9] in as... Read More
-
[LeetCode February Challange] Day 24 - Score of Parentheses
Given a balanced parentheses string S, compute the score of the string based on the following rule: () has score 1 AB has score A + B, where A and B are balanced parentheses strings. (A) has score 2 * A, where A is a balanced parentheses string. Example 1: Input: "()" Output: 1 Example 2: Input: "(())" Output: 2 Example 3: Input... Read More
-
[LeetCode February Challange] Day 23 - Search a 2D Matrix II
Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom. Example 1: Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[1... Read More
-
[LeetCode February Challange] Day 22 - Longest Word in Dictionary through Deleting
Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string. Example 1: Input: s ... Read More
-
[LeetCode February Challange] Day 21 - Broken Calculator
On a broken calculator that has a number showing on its display, we can perform two operations: Double: Multiply the number on the display by 2, or; Decrement: Subtract 1 from the number on the display. Initially, the calculator is displaying the number X. Return the minimum number of operations needed to display the number Y. Example ... Read More
-
[LeetCode February Challange] Day 20 - Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one’s added together. 12 is written as XII, which is simply X ... Read More
-
[LeetCode February Challange] Day 19 - Minimum Remove to Make Valid Parentheses
Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: It is the empty string, contains only lowercase char... Read More
-
[LeetCode February Challange] Day 18 - Arithmetic Slices
A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequences: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The following sequence is not arithmetic. 1, 1, 2, 5, 7 A zero-indexed array A consisting of N numb... Read More
-
[LeetCode February Challange] Day 17 - Container With Most Water
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. Notice that you may not slant the ... Read More
-
[LeetCode February Challange] Day 16 - Letter Case Permutation
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create. You can return the output in any order. Example 1: Input: S = "a1b2" Output: ["a1b2","a1B2","A1b2","A1B2"] Example 2: Input: S = "3z4" Output: ["3z4","3Z4"] Example 3: ... Read More
-
[LeetCode February Challange] Day 15 - The K Weakest Rows in a Matrix
You are given an m x n binary matrix mat of 1’s (representing soldiers) and 0’s (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1’s will appear to the left of all the 0’s in each row. A row i is weaker than a row j if one of the following is true: The number of soldiers in row i is less than... Read More
-
[LeetCode February Challange] Day 14 - Is Graph Bipartite?
There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties: There are no self-edg... Read More
-
[LeetCode February Challange] Day 13 - Shortest Path in Binary Matrix
In an N by N square grid, each cell is either empty (0) or blocked (1). A clear path from top-left to bottom-right has length k if and only if it is composed of cells C_1, C_2, ..., C_k such that: Adjacent cells C_i and C_{i+1} are connected 8-directionally (ie., they are different and share an edge or corner) C_1 is at location (0, 0) (i... Read More
-
[LeetCode February Challange] Day 12 - Number of Steps to Reduce a Number to Zero
Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it. Example 1: Input: num = 14 Output: 6 Explanation: Step 1) 14 is even; divide by 2 and obtain 7. Step 2) 7 is odd; subtract 1 and obtain 6. Step 3) 6 is even; ... Read More
-
[LeetCode February Challange] Day 11 - Valid Anagram
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: s = "anagram", t = "nagaram" Output: true Example 2: Input: s = "rat", t = "car" Output: false Note: You may assume the string contains only lowercase alphabets. Follow up: What if the inputs contain unicode characters? How would you ad... Read More
-
[LeetCode February Challange] Day 10 - Copy List with Random Pointer
A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and r... Read More
-
[LeetCode February Challange] Day 9 - Convert BST to Greater Tree
Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST. As a reminder, a binary search tree is a tree that satisfies these constraints: The left subtree of a node contains only nodes with keys ... Read More
-
[LeetCode February Challange] Day 8 - Peeking Iterator
Design an iterator that supports the peek operation on a list in addition to the hasNext and the next operations. Implement the PeekingIterator class: PeekingIterator(int[] nums) Initializes the object with the given integer array nums. int next() Returns the next element in the array and moves the pointer to the next element. bool hasN... Read More
-
[LeetCode February Challange] Day 7 - Shortest Distance to a Character
Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s. The distance between two indices i and j is abs(i - j), where abs is the absolute value function. Example 1: Input: s = "loveleetcode"... Read More
-
[LeetCode February Challange] Day 6 - Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example: Input: [1,2,3,null,5,null,4] Output: [1, 3, 4] Explanation: 1 <--- / \ 2 3 <--- \ \ 5 4 <--- Solution Time complexity : O(n) Space c... Read More
-
[LeetCode February Challange] Day 5 - Simplify Path
Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path. In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e.... Read More
-
[LeetCode February Challange] Day 4 - Longest Harmonious Subsequence
We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1. Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences. A subsequence of array is a sequence that can be derived from the array by deleting some or no elem... Read More
-
[LeetCode February Challange] Day 3 - Linked List Cycle
Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail’s next pointer is connected to. Note that pos is not pa... Read More
-
[LeetCode February Challange] Day 2 - Trim a Binary Search Tree
Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node’s descendant should remain a descendant). It can be proven that there is ... Read More
-
[LeetCode February Challange] Day 1 - Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight). Note: Note that in some languages such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer’s internal b... Read More
-
750. Number Of Corner Rectangles
Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner rectangle is 4 distinct 1s on the grid that form an axis-aligned rectangle. Note that only the corners need to have the value 1. Also, all four 1s used must be distinct. Example 1: Input: grid = [[1, 0, 0, 1, 0], [0, 0, 1, 0, 1], [0, 0, 0, 1, 0], ... Read More
-
[LeetCode January Challange] Day 31 - Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order). The replacement must be in place and use only constant extra memory. Example 1: Input: nums = [1,2,3]... Read More
-
[LeetCode January Challange] Day 30 - Minimize Deviation in Array
You are given an array nums of n positive integers. You can perform two types of operations on any element of the array any number of times: If the element is even, divide it by 2. For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2]. If the element ... Read More
-
[LeetCode January Challange] Day 29 - Vertical Order Traversal of a Binary Tree
Given the root of a binary tree, calculate the vertical order traversal of the binary tree. For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0). The vertical order traversal of a binary tree is a list of top-to-bottom or... Read More
-
[LeetCode January Challange] Day 28 - Smallest String With A Given Numeric Value
The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on. The numeric value of a string consisting of lowercase characters is defined as the sum of its characters’ numeric values. For example, the numeric... Read More
-
161. One Edit Distance
Given two strings s and t, return true if they are both one edit distance apart, otherwise return false. A string s is said to be one distance apart from a string t if you can: Insert exactly one character into s to get t. Delete exactly one character from s to get t. Replace exactly one character of s with a different character to get ... Read More
-
[LeetCode January Challange] Day 27 - Concatenation of Consecutive Binary Numbers
Given an integer n, return *the **decimal value** of the binary string formed by concatenating the binary representations of 1 to n in order, **modulo** 10^9 + 7*. Example 1: Input: n = 1 Output: 1 Explanation: "1" in binary corresponds to the decimal value 1. Example 2: Input: n = 3 Output: 27 Explanation: In binary, 1, 2, and 3 correspon... Read More
-
[LeetCode January Challange] Day 25 - Check If All 1's Are at Least Length K Places Away
Given an array nums of 0s and 1s and an integer k, return True if all 1’s are at least k places away from each other, otherwise return False. Example 1: Input: nums = [1,0,0,0,1,0,0,1], k = 2 Output: true Explanation: Each of the 1s are at least 2 places away from each other. Example 2: Input: nums = [1,0,0,1,0,1], k = 2 Output: false E... Read More
-
[LeetCode January Challange] Day 24 - Merge k Sorted Lists
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Example 1: Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into on... Read More
-
[LeetCode January Challange] Day 23 - Sort the Matrix Diagonally
A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix’s end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[4][2]. Given an m x n matr... Read More
-
[LeetCode January Challange] Day 22 - Determine if Two Strings Are Close
Two strings are considered close if you can attain one from the other using the following operations: Operation 1: Swap any two existing characters. For example, abcde -> aecdb Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character. ... Read More
-
Nested List Weight Sum
You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. The depth of an integer is the number of lists that it is inside of. For example, the nested list [1,[2,2],[[3],2],1] has each integer’s value set to its depth. Return the sum of each integer in ne... Read More
-
[LeetCode January Challange] Day 21 - Find the Most Competitive Subsequence
Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k. An array’s subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array. We define that a subsequence a is more competitive than a subsequence b (of the same length) if in the first position w... Read More
-
[LeetCode January Challange] Day 20 - Valid Parentheses
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Example 1: Input: s = "()" Output: true Example 2: Input: s = "()[]{}" Out... Read More
-
[LeetCode January Challange] Day 19 - Longest Palindromic Substring
Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Example 3: Input: s = "a" Output: "a" Example 4: Input: s = "ac" Output: "a" Constraints: 1 <= s.length <= 1000 s consist of on... Read More
-
[LeetCode January Challange] Day 18 - Max Number of K-Sum Pairs
You are given an integer array nums and an integer k. In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array. Return the maximum number of operations you can perform on the array. Example 1: Input: nums = [1,2,3,4], k = 5 Output: 2 Explanation: Starting with nums = [1,2,3,4]: - Remove numb... Read More
-
[LeetCode January Challange] Day 17 - Count Sorted Vowel Strings
Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted. A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet. Example 1: Input: n = 1 Output: 5 Explanation: The 5 sorted strings that consist of vo... Read More
-
[LeetCode January Challange] Day 16 - Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4] and k = 2 Output: 5 Example 2: Input: [3,2,3,1,2,4,5,5,6] and k = 4 Output: 4 Note: You may assume k is always valid, 1 ≤ k ≤ array’s length. Solution Min-Heap T... Read More
-
[LeetCode January Challange] Day 15 - Get Maximum in Generated Array
You are given an integer n. An array nums of length n + 1 is generated in the following way: nums[0] = 0 nums[1] = 1 nums[2 * i] = nums[i] when 2 <= 2 * i <= n nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n Return the maximum integer in the array nums. Example 1: I... Read More
-
[LeetCode January Challange] Day 14 - Minimum Operations to Reduce X to Zero
You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations. Return the minimum number of operations to reduce x to exactly 0 if it’s possible, otherwise, return -1. ... Read More
-
[LeetCode January Challange] Day 13 - Boats to Save People
The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at most limit. Return the minimum number of boats to carry every given person. (It is guaranteed each person can be carried by a boat.) Example 1: Inp... Read More
-
[LeetCode January Challange] Day 12 - Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example 1: Input: l1 = ... Read More
-
[LeetCode January Challange] Day 11 - Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is equal to m + n) to hold additional elements from nums2. Example 1: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2... Read More
-
Find Root of N-Ary Tree
You are given all the nodes of an N-ary tree as an array of Node objects, where each node has a unique value. Return the root of the N-ary tree. Custom testing: An N-ary tree can be serialized as represented in its level order traversal where each group of children is separated by the null value (see examples). For example, the above tree ... Read More
-
[LeetCode January Challange] Day 9 - Word Ladder
Given two words beginWord and endWord, and a dictionary wordList, return the length of the shortest transformation sequence from beginWord to endWord, such that: Only one letter can be changed at a time. Each transformed word must exist in the word list. Return 0 if there is no such transformation sequence. Example 1: Input: beginWord =... Read More
-
[LeetCode January Challange] Day 8 - Check If Two String Arrays are Equivalent
Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. A string is represented by an array if the array elements concatenated in order forms the string. Example 1: Input: word1 = ["ab", "c"], word2 = ["a", "bc"] Output: true Explanation: word1 represents string "ab" + "c" -> "... Read More
-
Palindrome Permutation
Given a string, determine if a permutation of the string could form a palindrome. Example 1: Input: "code" Output: false Example 2: Input: "aab" Output: true Example 3: Input: "carerac" Output: true Solution Time complexity : O(n) Space complexity : O(1) class Solution { public: bool canPermutePalindrome(string s) { bit... Read More
-
[LeetCode January Challange] Day 7 - Longest Substring Without Repeating Characters
Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The... Read More
-
[LeetCode January Challange] Day 6 - Kth Missing Positive Number
Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Find the k-th positive integer that is missing from this array. Example 1: Input: arr = [2,3,4,7,11], k = 5 Output: 9 Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9. Example 2: Inp... Read More
-
[LeetCode January Challange] Day 5 - Remove Duplicates from Sorted List II
Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well. Example 1: Input: head = [1,2,3,3,4,4,5] Output: [1,2,5] Example 2: Input: head = [1,1,1,2,3] Output: [2,3] Constraints: The number of nodes in the list is... Read More
-
[LeetCode January Challange] Day 4 - Merge Two Sorted Lists
Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists. Example 1: Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: Input: l1 = [], l2 = [] Output: [] Example 3: Input: l1 = [], l2 = [0] Output: [0] Constraints: The number of no... Read More
-
[LeetCode January Challange] Day 3 - Beautiful Arrangement
Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true: perm[i] is divisible by i. i is divisible by perm[i]. Given an integer n, return the number of the beautiful arrangements that you c... Read More
-
[LeetCode January Challange] Day 2 - Find a Corresponding Node of a Binary Tree in a Clone of That Tree
Given two binary trees original and cloned and given a reference to a node target in the original tree. The cloned tree is a copy of the original tree. Return a reference to the same node in the cloned tree. Note that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the clon... Read More
-
[LeetCode January Challange] Day 1 - Check Array Formation Through Concatenation
You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i]. Return true if it is possible to form the array arr from piec... Read More
-
[LeetCode December Challange] Day 13 - Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent. Find ... Read More
-
[LeetCode December Challange] Day 12 - Smallest Subtree with all the Deepest Nodes
Given the root of a binary tree, the depth of each node is the shortest distance to the root. Return the smallest subtree such that it contains all the deepest nodes in the original tree. A node is called the deepest if it has the largest depth possible among any node in the entire tree. The subtree of a node is tree consisting of that node, ... Read More
-
[LeetCode December Challange] Day 11 - Remove Duplicates from Sorted Array II
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array; you must do this by modifying the input array in-place with O(1) extra memory. Clarification: Confused why the returned value is an integer, but your answer is an array... Read More
-
[LeetCode December Challange] Day 10 - Valid Mountain Array
Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some i with 0 < i < arr.length - 1 such that: arr[0] < arr[1] < ... < arr[i - 1] < A[i] arr[i] > ... Read More
-
[LeetCode December Challange] Day 9 - Binary Search Tree Iterator
Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element... Read More
-
[LeetCode December Challange] Day 8 - Pairs of Songs With Total Durations Divisible by 60
You are given a list of songs where the i-th song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0. Example 1: Input: time = [30,20,150,100,40] Output: 3 Explana... Read More
-
[LeetCode December Challange] Day 7 - Spiral Matrix II
Given a positive integer n, generate an n x n matrix filled with elements from 1 to n^2 in spiral order. Example 1: Input: n = 3 Output: [[1,2,3],[8,9,4],[7,6,5]] Example 2: Input: n = 1 Output: [[1]] Constraints: 1 <= n <= 20 Solution Time complexity : O(n^2) Space complexity : O(1) class Solution { public: v... Read More
-
Shortest Word Distance
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. Example: Assume that words = ["practice", "makes", "perfect", "coding", "makes"]. Input: word1 = "coding", word2 = "practice" Output: 3 Input: word1 = "makes", word2 = "coding" Output: 1 Note: You may assume that word1... Read More
-
[LeetCode December Challange] Day 6 - Populating Next Right Pointers in Each Node II
Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL. Follow up: You may only use constant extra space. Recursive ... Read More
-
[LeetCode December Challange] Day 5 - Can Place Flowers
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0’s and 1’s, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-... Read More
-
[LeetCode December Challange] Day 4 - The kth Factor of n
Given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0. Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or return -1 if n has less than k factors. Example 1: Input: n = 12, k = 3 Output: 3 Explanation: Factors list is [1, 2, 3, 4, 6, 12], the... Read More
-
[LeetCode December Challange] Day 3 - Increasing Order Search Tree
Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child. Example 1: Input: root = [5,3,6,2,4,null,8,1,null,null,null,7,9] Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9] Example 2: ... Read More
-
[LeetCode December Challange] Day 2 - Linked List Random Node
Given a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen. Follow up: What if the linked list is extremely large and its length is unknown to you? Could you solve this efficiently without using extra space? Example: // Init a singly linked list [1,2,3]. ListNode he... Read More
-
Cooperative project - PHM program
Read More
-
[LeetCode December Challange] Day 1 - Maximum Depth of Binary Tree
Given the root of a binary tree, return its maximum depth. A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 3 Example 2: Input: root = [1,null,2] Output: 2 Example 3: Input: root = [] Output: 0 Example ... Read More
-
[LeetCode November Challange] Day 3 - Consecutive Characters
Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character. Return the power of the string. Example 1: Input: s = "leetcode" Output: 2 Explanation: The substring "ee" is of length 2 with the character 'e' only. Example 2: Input: s = "abbcccddddeeeeedcba" Output: 5 Explanat... Read More
-
[LeetCode November Challange] Day 2 - Insertion Sort List
Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list. With each iteration one element (red) is removed from the input data and inserted in-place into the sorted list Algorithm of Insertion Sort: Insertion sort iterates, consumin... Read More
-
[LeetCode November Challange] Day 1 - Convert Binary Number in a Linked List to Integer
Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number. Return the decimal value of the number in the linked list. Example 1: Input: head = [1,0,1] Output: 5 Explanation: (101) in base 2 = (5) in base 10 Example 2:... Read More
-
[LeetCode October Challange] Day 31 - Recover Binary Search Tree
You are given the root of a binary search tree (BST), where exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure. Follow up: A solution using O(n) space is pretty straight forward. Could you devise a constant space solution? Example 1: Input: root = [1,3,null,null,2] Output: [3,1,null,null,2]... Read More
-
[LeetCode October Challange] Day 30 - Number of Longest Increasing Subsequence
Given an integer array nums, return the number of longest increasing subsequences. Example 1: Input: nums = [1,3,5,4,7] Output: 2 Explanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7]. Example 2: Input: nums = [2,2,2,2,2] Output: 5 Explanation: The length of longest continuous increasing subsequence is 1, and ... Read More
-
[LeetCode October Challange] Day 29 - Maximize Distance to Closest Person
You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the i-th seat, and seats[i] = 0 represents that the i-th seat is empty (0-indexed). There is at least one empty seat, and at least one person sitting. Alex wants to sit in the seat such that the distance between him and the closest person to hi... Read More
-
[LeetCode October Challange] Day 28 - Summary Ranges
You are given a sorted unique integer array nums. Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums. Each range [a,b] in the list should be output as: "... Read More
-
[LeetCode October Challange] Day 27 - Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail’s next pointer is connected to. Note that pos ... Read More
-
[LeetCode October Challange] Day 26 - Champagne Tower
We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100-th row. Each glass holds one cup of champagne. Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and... Read More
-
[LeetCode October Challange] Day 25 - Stone Game IV
Alice and Bob take turns playing a game, with Alice starting first. Initially, there are n stones in a pile. On each player’s turn, that player makes a move consisting of removing any non-zero square number of stones in the pile. Also, if a player cannot make a move, he/she loses the game. Given a positive integer n. Return True if and only ... Read More
-
[LeetCode October Challange] Day 24 - Bag of Tokens
You have an initial power of P, an initial score of 0, and a bag of tokens where tokens[i] is the value of the i-th token (0-indexed). Your goal is to maximize your total score by potentially playing each token in one of two ways: If your current power is at least tokens[i], you may play the i-th token face up, losing tokens[i] power and gai... Read More
-
702. Search in a Sorted Array of Unknown Size
Given an integer array sorted in ascending order, write a function to search target in nums. If target exists, then return its index, otherwise return -1. However, the array size is unknown to you. You may only access the array using an ArrayReader interface, where ArrayReader.get(k) returns the element of the array at index k (0-indexed). You... Read More
-
[LeetCode October Challange] Day 23 - 132 pattern
Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132 pattern in nums, otherwise, return false. Follow up: The O(n^2) is trivial, could you come up with the O(n logn) or the O(n) solution? E... Read More
-
[LeetCode October Challange] Day 22 - Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 2 Example 2: Input: root = [2,null,3,null,4,null,5,null,6] Output: 5 Constraints... Read More
-
[LeetCode October Challange] Day 21 - Asteroid Collision
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collisions. If two asteroids meet, th... Read More
-
253. Meeting Rooms II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required. Example 1: Input: [[0, 30],[5, 10],[15, 20]] Output: 2 Example 2: Input: [[7,10],[2,4]] Output: 1 NOTE: input types have been changed on April 15, 2019. Please reset to default ... Read More
-
[LeetCode October Challange] Day 20 - Clone Graph
Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors. class Node { public int val; public List<Node> neighbors; } Test case format: For simplicity sake, each node’s value is the same as the nod... Read More
-
[LeetCode October Challange] Day 19 - Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) We may rotate the i-th domino, so that A[i] and B[i] swap values. Return the minimum number of rotations so that all the values in A are the same, or all the values in B ... Read More
-
[LeetCode October Challange] Day 18 - Best Time to Buy and Sell Stock IV
You are given an integer array prices where prices[i] is the price of a given stock on the i-th day. Design an algorithm to find the maximum profit. You may complete at most k transactions. Notice that you may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again). Example 1: Input: k = 2, pric... Read More
-
[LeetCode October Challange] Day 17 - Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T', for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. Example 1: Input: s = "AAAA... Read More
-
[LeetCode October Challange] Day 16 - Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row. Example 1: Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,50]], target = 3 Outpu... Read More
-
[LeetCode October Challange] Day 15 - Rotate Array
Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could you do it in-place with O(1) extra space? Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1... Read More
-
170. Two Sum III - Data structure design
Design a data structure that accepts a stream of integers and checks if it has a pair of integers that sum up to a particular value. Implement the TwoSum class : TwoSum() Initializes the TwoSum object, with an empty array initially. void add(int number) Adds number to the data structure. boolean find(int value) Returns true if there exis... Read More
-
[LeetCode October Challange] Day 14 - House Robber II
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adja... Read More
-
[LeetCode October Challange] Day 13 - Sort List
Given the head of a linked list, return the list after sorting it in ascending order. Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)? Example 1: Input: head = [4,2,1,3] Output: [1,2,3,4] Example 2: Input: head = [-1,5,3,4,0] Output: [-1,0,3,4,5] Example 3: Input: head = [] Output: [] ... Read More
-
[LeetCode October Challange] Day 12 - Buddy Strings
Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false. Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at A[i] and A[j]. For example, swapping at indices 0 and 2 in "abcd" results in "cba... Read More
-
[LeetCode October Challange] Day 11 - Remove Duplicate Letters
Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Note: This question is the same as 1081 Example 1: Input: s = "bcabc" Output: "abc" Example 2: Input: s = "cbacdcbc" Output: "acdb" Constraints: ... Read More
-
[LeetCode October Challange] Day 10 - Minimum Number of Arrows to Burst Balloons
There are some spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coordinates don’t matter, and hence the x-coordinates of start and end of the diameter suffice. The start is always smaller than the end. An arrow can be shot u... Read More
-
[LeetCode October Challange] Day 9 - Serialize and Deserialize BST
Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment. Design an algorithm to serialize and deserialize a binary search tree. There is no restriction ... Read More
-
[LeetCode October Challange] Day 8 - Binary Search
Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1. Example 1: Input: nums = [-1,0,3,5,9,12], target = 9 Output: 4 Explanation: 9 exists in nums and its index is 4 Example 2: Input: nums = [-1,0,3,5,9,1... Read More
-
[LeetCode October Challange] Day 7 - Rotate List
Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Explanation: rotate 1 steps to the right: 5->1->2->3->4->NULL rotate 2 steps to the right: 4->5->1->2->3->NULL Example 2: I... Read More
-
[LeetCode October Challange] Day 6 - Insert into a Binary Search Tree
You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST. Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can ... Read More
-
[LeetCode October Challange] Day 5 - Complement of Base 10 Integer
Every non-negative integer N has a binary representation. For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on. Note that except for N = 0, there are no leading zeroes in any binary representation. The complement of a binary representation is the number in binary you get when changing every 1 to a 0 and 0 to... Read More
-
[LeetCode October Challange] Day 4 - Remove Covered Intervals
Given a list of intervals, remove all intervals that are covered by another interval in the list. Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d. After doing so, return the number of remaining intervals. Example 1: Input: intervals = [[1,4],[3,6],[2,8]] Output: 2 Explanation: Interval [3,6] is covered by [2... Read More
-
[LeetCode October Challange] Day 3 - K-diff Pairs in an Array
Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array. A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true: 0 <= i, j < nums.length i != j a <= b b - a == k Example 1: Input: nums = [3,1,4,1,5], k = 2 Output: 2 Exp... Read More
-
Maximum Distance in Arrays
Given m arrays, and each array is sorted in ascending order. Now you can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a-b|. Your task is to find the maximum distance. Example 1: Input: [[1,2,3], [4,5], [1,... Read More
-
[LeetCode October Challange] Day 2 - Combination Sum
Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at le... Read More
-
[LeetCode October Challange] Day 1 - Number of Recent Calls
You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: RecentCounter() Initializes the counter with zero recent requests. int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has ... Read More
-
Word Squares
Given a set of words (without duplicates), find all word squares you can build from them. A sequence of words forms a valid word square if the k-th row and column read the exact same string, where 0 ≤ k < max(numRows, numColumns). For example, the word sequence ["ball","area","lead","lady"] forms a word square because each word reads the sa... Read More
-
[LeetCode September Challange]Day30-First Missing Positive
Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: Input: [7,8,9,11,12] Output: 1 Follow up: Your algorithm should run in O(n) time and uses constant extra space. Solution Time complexity : O(n) Space complexity : O(1) clas... Read More
-
[LeetCode September Challange]Day29-Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. Note: The same word in the dictionary may be reused multiple times in the segmentation. You may assume the dictionary does not contain duplicate words. ... Read More
-
[LeetCode September Challange]Day28-Subarray Product Less Than K
Your are given an array of positive integers nums. Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less than k. Example 1: Input: nums = [10, 5, 2, 6], k = 100 Output: 8 Explanation: The 8 subarrays that have product less than 100 are: [10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [... Read More
-
[LeetCode September Challange]Day27-Evaluate Division
You are given equations in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating-point number). Given some queries, return the answers. If the answer does not exist, return -1.0. The input is always valid. You may assume that evaluating the queries will result in no division by zero and there... Read More
-
[LeetCode September Challange]Day26-Teemo Attacking
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning time duration per Teemo’s attacking, you need to output the total time that Ashe is in poisoned condition. You may assume that Teemo attacks at the v... Read More
-
Insert into a Sorted Circular Linked List
Given a node from a Circular Linked List which is sorted in ascending order, write a function to insert a value insertVal into the list such that it remains a sorted circular list. The given node can be a reference to any single node in the list, and may not be necessarily the smallest value in the circular list. If there are multiple suitable ... Read More
-
[LeetCode September Challange]Day25-Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Input: [10,2] Output: "210" Example 2: Input: [3,30,34,5,9] Output: "9534330" Note: The result may be very large, so you need to return a string instead of an integer. Solution Time complexity : O(nlogn) Space complexity : O(n) class ... Read More
-
[LeetCode September Challange]Day24-Find the Difference
Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in t. Example: Input: s = "abcd" t = "abcde" Output: e Explanation: 'e' is the letter that was added. Solution Time complexity : O(n) Spa... Read More
-
[LeetCode September Challange]Day23-Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations. Return the starting gas station’s index if you can travel... Read More
-
[LeetCode September Challange]Day22-Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Note: The algorithm should run in linear time and in O(1) space. Example 1: Input: [3,2,3] Output: [3] Example 2: Input: [1,1,1,3,3,2,2,2] Output: [1,2] Solution Time complexity : O(n) Space complexity : O(1) class Solution { public: vector<... Read More
-
Inorder Successor in BST II
Given a node in a binary search tree, find the in-order successor of that node in the BST. If that node has no in-order successor, return null. The successor of a node is the node with the smallest key greater than node.val. You will have direct access to the node but not to the root of the tree. Each node will have a reference to its parent ... Read More
-
[LeetCode September Challange]Day21-Car Pooling
You are driving a vehicle that has capacity empty seats initially available for passengers. The vehicle only drives east (ie. it cannot turn around and drive west.) Given a list of trips, trip[i] = [num_passengers, start_location, end_location] contains information about the i-th trip: the number of passengers that must be picked up, and the l... Read More
-
[LeetCode September Challange]Day20-Unique Paths III
On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square. There is exactly one starting square. 2 represents the ending square. There is exactly one ending square. 0 represents empty squares we can walk over. -1 represents obstacles that we cannot walk over. Return the number of 4-directional walks fr... Read More
-
[LeetCode September Challange]Day19-Sequential Digits
An integer has sequential digits if and only if each digit in the number is one more than the previous digit. Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. Example 1: Input: low = 100, high = 300 Output: [123,234] Example 2: Input: low = 1000, high = 13000 Output: [1234,2345,3456,456... Read More
-
[LeetCode September Challange]Day18-Best Time to Buy and Sell Stock
Say you have an array for which the i-th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Note that you cannot sell a stock before you buy one. Example 1: Input: [7,1,5,3,6,4] Output: 5... Read More
-
[LeetCode September Challange]Day17-Robot Bounded In Circle
On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions: "G" : go straight 1 unit. "L" : turn 90 degrees to the left. "R" : turn 90 degress to the right. The robot performs the instructions given in order, and repeats them forever. Return true if and only if there exis... Read More
-
[LeetCode September Challange]Day16-Maximum XOR of Two Numbers in an Array
Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 ≤ i ≤ j < n. Follow up: Could you do this in O(n) runtime? Example 1: Input: nums = [3,10,5,25,2,8] Output: 28 Explanation: The maximum result is 5 XOR 25 = 28. Example 2: Input: nums = [0] Output: 0 Example 3: Input: nums = [2,4] Output: 6 Example ... Read More
-
[LeetCode September Challange]Day15-Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string. If the last word does not exist, return 0. Note: A word is defined as a maximal substring consisting of non-space characters only. Example... Read More
-
[LeetCode September Challange]Day14-House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given a l... Read More
-
[LeetCode September Challange]Day13-Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1: Input: intervals = [[1,3],[6,9]], newInterval = [2,5] Output: [[1,5],[6,9]] Example 2: Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]... Read More
-
[LeetCode September Challange]Day12-Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Note: All numbers will be positive integers. The solution set must not contain duplicate combinations. Example 1: Input: k = 3, n = 7 Output: [[1,2,4]] Example 2:... Read More
-
[LeetCode September Challange]Day11-Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. Example 1: Input: [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Example 2: Input: [-2,0,-1] Output: 0 Explanation: The result cannot be 2, because [-2,-1] is not a subarray. Solutio... Read More
-
[LeetCode September Challange]Day10-Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit and position (called “bulls”) and how many digits match th... Read More
-
[LeetCode September Challange]Day9-Compare Version Numbers
Compare two version numbers version1 and version2. If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0. You may assume that the version strings are non-empty and contain only digits and the . character. The . character does not represent a decimal point and is used to separate number sequences. For insta... Read More
-
929. Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name. Besides lowercase letters, these emails may contain '.'s or '+'s. If you add periods ('.') between some characters in the local name part of an email address, mail s... Read More
-
[LeetCode September Challange]Day8-Sum of Root To Leaf Binary Numbers
Given a binary tree, each node has value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13. For all leaves in the tree, consider the numbers represented by the path from the root... Read More
-
157. Read N Characters Given Read4
Given a file and assume that you can only read the file using a given method read4, implement a method to read n characters. Method read4: The API read4 reads 4 consecutive characters from the file, then writes those characters into the buffer array buf. The return value is the number of actual characters read. Note that read4() has its own ... Read More
-
346. Moving Average from Data Stream
Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. Example: MovingAverage m = new MovingAverage(3); m.next(1) = 1 m.next(10) = (1 + 10) / 2 m.next(3) = (1 + 10 + 3) / 3 m.next(5) = (10 + 3 + 5) / 3 Solution Time complexity : O(1) Space complexity : O(n) class MovingAverage { p... Read More
-
[LeetCode September Challange]Day7-Word Pattern
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Example 1: Input: pattern = "abba", str = "dog cat cat dog" Output: true Example 2: Input:pattern = "abba", str = "dog cat cat fish" Output: false Ex... Read More
-
[LeetCode September Challange]Day6-Image Overlap
Two images A and B are given, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.) We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image. After, the overlap of this translation is the number of positions tha... Read More
-
[LeetCode September Challange]Day5-All Elements in Two Binary Search Trees
Given two binary search trees root1 and root2. Return a list containing all the integers from both trees sorted in ascending order. Example 1: Input: root1 = [2,1,4], root2 = [1,0,3] Output: [0,1,1,2,3,4] Example 2: Input: root1 = [0,-10,10], root2 = [5,1,7,0,2] Output: [-10,0,0,1,2,5,7,10] Example 3: Input: root1 = [], root2 = [5,1,7,0,... Read More
-
[LeetCode September Challange]Day4-Partition Labels
A string S of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts. Example 1: Input: S = "ababcbacadefegdehijhklij" Output: [9,7,8] Explanation: The partition is "ababcbaca", "defegd... Read More
-
[LeetCode September Challange]Day3-Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000. Example 1: Input: "abab" Output: True Explanation: It's the substring "ab" twice. Example ... Read More
-
[LeetCode September Challange]Day2-Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute difference between i and j is at most k. Example 1: Input: nums = [1,2,3,1], k = 3, t = 0 Output: true Example 2: Input: nums = [1,0,1,1], k = 1, t = 2 Out... Read More
-
[LeetCode September Challange]Day1-Largest Time for Given Digits
Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour time is 00:00, and the largest is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight. Return the answer as a string of length 5. If no valid time can be made, return an empty string. Example 1: Input: [1,2,3,4... Read More
-
[LeetCode August Challange]Day31-Delete Node in a BST
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion can be divided into two stages: Search for a node to remove. If the node is found, delete the node. Note: Time complexity should be O(height of tree). Exampl... Read More
-
[LeetCode August Challange]Day30-Largest Component Size by Common Factor
Given a non-empty array of unique positive integers A, consider the following graph: There are A.length nodes, labelled A[0] to A[A.length - 1]; There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1. Return the size of the largest connected component in the graph. Example 1: Input: [4,... Read More
-
[LeetCode August Challange]Day29-Pancake Sorting
Given an array of integers A, We need to sort the array performing a series of pancake flips. In one pancake flip we do the following steps: Choose an integer k where 0 <= k < A.length. Reverse the sub-array A[0...k]. For example, if A = [3,2,1,4] and we performed a pancake flip choosing k = 2</font>**, we reverse the sub-array... Read More
-
[LeetCode August Challange]Day28-Implement Rand10() Using Rand7()
Given the API rand7 which generates a uniform random integer in the range 1 to 7, write a function rand10 which generates a uniform random integer in the range 1 to 10. You can only call the API rand7 and you shouldn’t call any other API. Please don’t use the system’s Math.random(). Notice that Each test case has one argument n, the number of t... Read More
-
[LeetCode August Challange]Day27-Find Right Interval
Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i, which can be called that j is on the “right” of i. For any interval i, you need to store the minimum interval j’s index, which means that the interval j has the minimum start poi... Read More
-
[LeetCode August Challange]Day26-Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Bu... Read More
-
[LeetCode August Challange]Day25-Minimum Cost For Tickets
In a country popular for train travel, you have planned some train travelling one year in advance. The days of the year that you will travel is given as an array days. Each day is an integer from 1 to 365. Train tickets are sold in 3 different ways: a 1-day pass is sold for costs[0] dollars; a 7-day pass is sold for costs[1] dollars; a... Read More
-
[LeetCode August Challange]Day24-Sum of Left Leaves
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. Solution Time complexity : O(n) Space complexity : O(n) /** * Definition for a binary tree node. * struct TreeNode { * int val; * ... Read More
-
[LeetCode August Challange]Day23-Stream of Characters
Implement the StreamChecker class as follows: StreamChecker(words): Constructor, init the data structure with the given words. query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list. Example:... Read More
-
[LeetCode August Challange]Day22-Random Point in Non-overlapping Rectangles
Given a list of non-overlapping axis-aligned rectangles rects, write a function pick which randomly and uniformily picks an integer point in the space covered by the rectangles. Note: An integer point is a point that has integer coordinates. A point on the perimeter of a rectangle is included in the space covered by the rectangles. i-th ... Read More
-
[LeetCode August Challange]Day21-Sort Array By Parity
Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may return any answer array that satisfies this condition. Example 1: Input: [3,1,2,4] Output: [2,4,3,1] The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted. Note: 1 <= A.len... Read More
-
[LeetCode August Challange]Day20-Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not modify the values in the list’s nodes, only nodes itself may be changed. Example 1: Given 1->2->3->4, reorder it to 1->4->2->3. Example 2: Given 1->2->3->4->5, reorder it to 1->5->2->4->3. Solution ... Read More
-
[LeetCode August Challange]Day19-Goat Latin
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to “Goat Latin” (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end of the word.... Read More
-
[LeetCode August Challange]Day18-Numbers With Same Consecutive Differences
Return all non-negative integers of length N such that the absolute difference between every two consecutive digits is K. Note that every number in the answer must not have leading zeros except for the number 0 itself. For example, 01 has one leading zero and is invalid, but 0 is valid. You may return the answer in any order. Example 1: Input... Read More
-
[LeetCode August Challange]Day17-Distribute Candies to People
We distribute some number of candies, to a row of n = num_people people in the following way: We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person. Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and... Read More
-
[LeetCode August Challange]Day16-Best Time to Buy and Sell Stock III
Say you have an array for which the i-th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again). Example 1: Input: [3,3,5,0,0,3,1,4] Output:... Read More
-
[LeetCode August Challange]Day15-Non-overlapping Intervals
Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Example 1: Input: [[1,2],[2,3],[3,4],[1,3]] Output: 1 Explanation: [1,3] can be removed and the rest of intervals are non-overlapping. Example 2: Input: [[1,2],[1,2],[1,2]] Output: 2 Explanation: You need... Read More
-
[LeetCode August Challange]Day14-Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not considered a palindrome here. Note: Assume the length of given string will not exceed 1,010. Example: Input: "abccccdd" Output: 7 Explanation: One ... Read More
-
[LeetCode August Challange]Day13-Iterator for Combination
Design an Iterator class, which has: A constructor that takes a string characters of sorted distinct lowercase English letters and a number combinationLength as arguments. A function next() that returns the next combination of length combinationLength in lexicographical order. A function hasNext() that returns True if and only if there e... Read More
-
[LeetCode August Challange]Day12-Pascal's Triangle II
Given a non-negative index k where k ≤ 33, return the k-th index row of the Pascal’s triangle. Note that the row index starts from 0. In Pascal’s triangle, each number is the sum of the two numbers directly above it. Example: Input: 3 Output: [1,3,3,1] Follow up: Could you optimize your algorithm to use only O(k) extra space? solution ... Read More
-
[LeetCode August Challange]Day11-H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index. According to the definition of h-index on Wikipedia: “A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.” Examp... Read More
-
[LeetCode August Challange]Day10-Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... Example 1: Input: "A" Output: 1 Example 2: Input: "AB" Output: 28 Example 3: Input: "ZY" Output: 701 Constraints: 1 <= s.length <= 7 s consists only ... Read More
-
[LeetCode August Challange]Day9-Rotting Oranges
In a given grid, each cell can have one of three values: the value 0 representing an empty cell; the value 1 representing a fresh orange; the value 2 representing a rotten orange. Every minute, any fresh orange that is adjacent (4-directionally) to a rotten orange becomes rotten. Return the minimum number of minutes that must elapse u... Read More
-
[LeetCode August Challange]Day8-Path Sum III
You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes). The tree has no more than 1,000 nodes and the values are in the range -1,000,000... Read More
-
[LeetCode August Challange]Day7-Vertical Order Traversal of a Binary Tree
Given a binary tree, return the vertical order traversal of its nodes values. For each node at position (X, Y), its left and right children respectively will be at positions (X-1, Y-1) and (X+1, Y-1). Running a vertical line from X = -infinity to X = +infinity, whenever the vertical line touches some nodes, we report the values of the nodes in... Read More
-
[LeetCode August Challange]Day6-Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? Example: Input: [4,3,2,7,8,2,3,1] Output: [2,3] solution Time complexity : O(n) Space complexity : O(1) class So... Read More
-
[LeetCode August Challange]Day5-Add and Search Word - Data structure design
Design a data structure that supports the following two operations: void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter. Example: addWord("bad") addWord("dad") addWord("mad") search("pad") -> false search("bad... Read More
-
[LeetCode August Challange]Day4-Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example 1: Input: 16 Output: true Example 2: Input: 5 Output: false Follow up: Could you solve it without loops/recursion? solution Time complexity : O(1) Space complexity : O(1) class Solution { public: bool isPowerOfFour(int num) { re... Read More
-
[LeetCode August Challange]Day3-Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: "A man, a plan, a canal: Panama" Output: true Example 2: Input: "race a car" Output: false Constraints: s consists only of prin... Read More
-
[LeetCode August Challange]Day2-Design HashSet
Design a HashSet without using any built-in hash table libraries. To be specific, your design should include these functions: add(value): Insert a value into the HashSet. contains(value): Return whether the value exists in the HashSet or not. remove(value): Remove a value in the HashSet. If the value does not exist in the HashSet, do no... Read More
-
[LeetCode August Challange]Day1-Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this word are capitals, like “USA”. All letters in this word are not capitals, like “leetcode”. Only the first letter in this word is capital, li... Read More
-
[LeetCode July Challange]Day31-Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps Example 2: Input: 3 Output: 3 Explanation: There are three ways ... Read More
-
[LeetCode July Challange]Day30-Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. Note: The same word in the dictionary may be reused multiple times in the segmentation. You may assume the dictionary does not con... Read More
-
[LeetCode July Challange]Day29-Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times) with the following restrictions: You may not engage in multiple transactions at the same time (... Read More
-
[LeetCode July Challange]Day28-Task Scheduler
You are given a char array representing tasks CPU need to do. It contains capital letters A to Z where each letter represents a different task. Tasks could be done without the original order of the array. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle. However, there is a non... Read More
-
[LeetCode July Challange]Day27-Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example, given inorder = [9,3,15,20,7] postorder = [9,15,7,20,3] return the following binary tree: 3 / \ 9 20 / \ 15 7 solution time complexity : O(nlogn) space complexity : ... Read More
-
[LeetCode July Challange]Day26-Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example 1: Input: 38 Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do it without any loop/recursion in O(1) runtime? solution time complexity : ... Read More
-
[LeetCode July Challange]Day25-Find Minimum in Rotated Sorted Array II
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). Find the minimum element. The array may contain duplicates. Example 1: Input: [1,3,5] Output: 1 Example 2: Input: [2,2,2,0,1] Output: 0 Note: This is a follow up problem to Find Minimum... Read More
-
[LeetCode July Challange]Day24-All Paths From Source to Target
Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and return them in any order. The graph is given as follows: the nodes are 0, 1, …, graph.length - 1. graph[i] is a list of all nodes j for which the edge (i, j) exists. Example: Input: [[1,2], [3], [3], []] Output: [[0,1,3],[0,2,3]] Explanation: ... Read More
-
[LeetCode July Challange]Day23-Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. Example: Input: [1,2,1,3,2,5] Output: [3,5] Note: The order of the result is not important. So in the above example, [5, 3] is also correct. Your algorithm should ru... Read More
-
[LeetCode July Challange]Day22-Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ [3], [20,9], [15,7] ] ... Read More
-
[LeetCode July Challange]Day21-Word Search
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. Example: board = [ ['A','B','C','E'], ['S','F','C','S'], ['A','D','E','E'] ... Read More
-
[LeetCode July Challange]Day20-Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. Example: Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5 solution time complexity : O(n) space complexity : O(1) /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNo... Read More
-
[LeetCode July Challange]Day19-Add Binary
Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010", b = "1011" Output: "10101" Constraints: Each string consists only of ‘0’ or ‘1’ characters. 1 <= a.length, b.len... Read More
-
[LeetCode July Challange]Day18-Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, return the ordering of courses you should take to finish all courses. ... Read More
-
[LeetCode July Challange]Day17-Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Note: You may assume k is always valid, 1 ≤ k ≤ number of unique elements. Your algorithm’s time complexity must be better than O(n log n), where n is the ... Read More
-
[LeetCode July Challange]Day16-Pow(x, n)
Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Output: 9.26100 Example 3: Input: 2.00000, -2 Output: 0.25000 Explanation: 2-2 = 1/22 = 1/4 = 0.25 Note: -100.0 < x < 100.0 n is a 32-bit signed integer, within the range [−231, 231 −... Read More
-
[LeetCode July Challange]Day15-Reverse Words in a String
Given an input string, reverse the string word by word. Example 1: Input: "the sky is blue" Output: "blue is sky the" Example 2: Input: " hello world! " Output: "world! hello" Explanation: Your reversed string should not contain leading or trailing spaces. Example 3: Input: "a good example" Output: "example good a" Explanation: You need... Read More
-
[LeetCode July Challange]Day14-Angle Between Hands of a Clock
Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand. Example 1: Input: hour = 12, minutes = 30 Output: 165 Example 2: Input: hour = 3, minutes = 30 Output: 75 Example 3: Input: hour = 3, minutes = 15 Output: 7.5 Example 4: Input: hour = 4, minutes = 50 Output: 155 ... Read More
-
[LeetCode July Challange]Day13-Same Tree
Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value. Example 1: Input: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3] Output: true Example 2: Input: 1 ... Read More
-
[LeetCode July Challange]Day12-Reverse Bits
Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000. E... Read More
-
[LeetCode July Challange]Day11-Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Example : Input: nums = [1,2,3] Output: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] solution time complexity : O(2^n) space complexity : O(2^n) (n : nums size) class Soluti... Read More
-
[LeetCode July Challange]Day10-Flatten a Multilevel Doubly Linked List
You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure, as shown in the example below. Flatten the list so th... Read More
-
[LeetCode July Challange]Day9-Maximum Width of Binary Tree
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a full binary tree, but some nodes are null. The width of one level is defined as the length between the end-nodes (the leftmost and right most non-null nodes in t... Read More
-
[LeetCode July Challange]Day8-3Sum
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate triplets. Example: Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] solution time co... Read More
-
[LeetCode July Challange]Day7-Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn’t have “lakes” (water inside that... Read More
-
[LeetCode July Challange]Day6-Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit. You may assume the integer does not contain any leading zero, except the number 0 itself. Example 1: Input:... Read More
-
[LeetCode July Challange]Day5-Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note : 0 <= x, y <= 2^31. Example : Input: x = 1, y = 4 Output: 2 Explanation: 1 (0 0 0 1) 4 (0 1 0 0) ↑ ↑ The above arrows poi... Read More
-
[LeetCode July Challange]Day4-Ugly Number II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example 1: Input: n = 10 Output: 12 Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note : 1 is typically treated as an ugly number. n does not exceed 1690. Hint : ... Read More
-
[LeetCode July Challange]Day3-Prison Cells After N Days
There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the cell is occupied or vacant changes according to the following rules: If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied. Otherwise, it becomes vacant. (Note that because the prison is... Read More
-
[LeetCode July Challange]Day2-Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ] ... Read More
-
[LeetCode July Challange]Day1-Arranging Coins
You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be formed. n is a non-negative integer and fits within the range of a 32-bit signed integer. example 1 n = 5 The coins can form the following rows: ¤ ¤ ¤... Read More
-
MQTT with wemos & win10
About MQTT Get started with Wemos D1 R2 Mosquitto (MQTT broker) Make sure the service named Mosquitto Broker is running on your computer. mosquitto_sub -h “localhost” (-p “9487” -u “username” -P “pwd”) -t “topic/#” (-d) mosquitto_pub -h “localhost” (-p “9487” -u “username” -P “pwd”) -m “Publishing Message” -t “topic/” PubSubClient (arduino ... Read More
-
Q-learning
Reinforcement Learning From A to Z by repeat again and again. Bellman Equation Learning from a reward after an action at a state in an environment. s : state a : action R : Reward V : Value : discount Markov Decision Process(MDP) Deterministic Search 100% chances take the action we want. Non-Deterministic Search not 100% chances take the ac... Read More
-
Win 10 & VM Ubuntu 18.04 - shared folder
VMware tools Reinstall VMware tools Copy & tar VMware tools Install VMware tools VMware settings VMware settings Set shared folder Mount shared folder Mount shared folder Read More
-
vscode with c++ Windows setup
Download & Install Visual Studio Code Download & Install MinGW-w64 Modify “Architecture” in Settings Modify “Destination folder” in Installation folder others default is fine Download & Install LLVM Download “Pre-Built Binaries” version Modify “system PATH” option Modify “Destination Folder” Copy data Copy data in “C:\mingw-w64\... Read More
-
SQL note
Intro SQL = Structured Query Language SQL lets you access and manipulate databases Syntax SQL keywords are NOT case sensitive : select is the same as SELECT. -- 抓出所有資料 SELECT * FROM table_name; Some of The Most Important SQL Commands : Commands Discription SELECT extracts data from a data... Read More
-
python note
一切都從這裡開始 if __name__ == '__main__': # 開始你想做的事, python以縮排當作'{}', 句尾不用加';' print("Hello Python") # 宣告變數,直接給值即可 x = 5 # 自動轉型為int y = "Shawn" # 自動轉型為str # 也可強制轉型 z = float("2") # z = 2.0 a = str(123) # a = "123" Function相關 # 宣告function def function_name(arg1, arg2, arg3 = default_value): # 做function該做的事 return (arg1 + arg2) # la... Read More
-
tennis game
使用JavaScript製作的簡單小遊戲,簡單的AI。 玩家利用「滑鼠」控制「左方」檔板。 「三分」為勝負判定。 Read More