0%

Difficult:Medium

題目

Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.

An interleaving of two strings s and t is a configuration where s and t are divided into n and m non-empty substrings respectively, such that:

s = s1 + s2 + … + sn
t = t1 + t2 + … + tm
|n - m| <= 1
The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + … or t1 + s1 + t2 + s2 + t3 + s3 + …
Note: a + b is the concatenation of strings a and b.

閱讀全文 »

前言

何謂Queue

Queue是一種先進先出(FIFO, First-In-First-Out)的資料結構,它與堆疊處理資料方式是不大一樣的,亦即資料處理是在不同邊進行,也就是資料由一端加入,由另一端刪除。生活中就有用到隊列的實例,如排隊買飲料第一個購買飲料的人,會先結帳。

閱讀全文 »

Difficult:Medium

題目

A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros.

For example, “0.1.2.201” and “192.168.1.1” are valid IP addresses, but “0.011.255.245”, “192.168.1.312” and “192.168@1.1“ are invalid IP addresses.
Given a string s containing only digits, return all possible valid IP addresses that can be formed by inserting dots into s. You are not allowed to reorder or remove any digits in s. You may return the valid IP addresses in any order.

閱讀全文 »

前言

什麼是 Stack?

stack是一種資料結構,資料像盤子一個一個往上疊,只能從最上面的開始拿取,採取先進後出的概念,即「Last In First Out」縮寫「LIFO」。

閱讀全文 »