原创 【LeetCode】Convert Sorted Array to Binary Search Tree(將有序數組轉換爲二叉搜索樹)

這道題是LeetCode裏的第108道題。 題目描述: 將一個按照升序排列的有序數組,轉換爲一棵高度平衡二叉搜索樹。 本題中,一個高度平衡二叉樹是指一個二叉樹每個節點 的左右兩個子樹的高度差的絕對值不超過 1。 示例: 給定有序數組:

原创 【LeetCode】Minimum Depth of Binary Tree(二叉樹的最小深度)

這道題是LeetCode裏的第111道題。 題目描述: 給定一個二叉樹,找出其最小深度。 最小深度是從根節點到最近葉子節點的最短路徑上的節點數量。 說明: 葉子節點是指沒有子節點的節點。 示例: 給定二叉樹 [3,9,20,null,n

原创 【Codewars】Josephus Permutation

Codewars裏的 5kyu Kata。 題目說明: This problem takes its name by arguably the most important event in the life of the ancien

原创 【Codewars】Maximum subarray sum

Codewars裏的 5kyu Kata。 題目說明: The maximum sum subarray problem consists in finding the maximum sum of a contiguous subse

原创 【Codewars】Is a number prime?

Codewars裏的 6kyu Kata。 題目說明: Description: Define a function that takes an integer argument and returns logical value tr

原创 【Codewars】Simple Pig Latin

Codewars裏的 5kyu Kata。 題目說明: Move the first letter of each word to the end of it, then add "ay" to the end of the word.

原创 【Codewars】Multi-tap Keypad Text Entry on an Old Mobile Phone

Codewars裏的 6kyu Kata。 題目說明: Description: Prior to having fancy iPhones, teenagers would wear out their thumbs sending

原创 【LeetCode】House Robber(打家劫舍)

這道題是LeetCode裏的第198道題。 題目描述: 你是一個專業的小偷,計劃偷竊沿街的房屋。每間房內都藏有一定的現金,影響你偷竊的唯一制約因素就是相鄰的房屋裝有相互連通的防盜系統,如果兩間相鄰的房屋在同一晚上被小偷闖入,系統會自動報

原创 【LeetCode】Best Time to Buy and Sell Stock II(買賣股票的最佳時機 II)

這道題是LeetCode裏的第122道題。 題目描述: 給定一個數組,它的第 i 個元素是一支給定股票第 i 天的價格。 設計一個算法來計算你所能獲取的最大利潤。你可以儘可能地完成更多的交易(多次買賣一支股票)。 注意:你不能同時參與多

原创 【LeetCode】Best Time to Buy and Sell Stock(買賣股票的最佳時機)

這道題是LeetCode裏的第121道題。 題目描述: 給定一個數組,它的第 i 個元素是一支給定股票第 i 天的價格。 如果你最多隻允許完成一筆交易(即買入和賣出一支股票),設計一個算法來計算你所能獲取的最大利潤。 注意你不能在買入股

原创 【Codewars】The Supermarket Queue

Codewars裏的 6kyu Kata。 題目說明: There is a queue for the self-checkout tills at the supermarket. Your task is write a func

原创 【Codewars】Shortest Word

Codewars裏的 7kyu Kata。 題目說明: Simple, given a string of words, return the length of the shortest word(s). String will ne

原创 【Codewars】Valid Braces

Codewars裏的 6kyu Kata。 題目說明: Write a function that takes a string of braces, and determines if the order of the braces

原创 【LeetCode】Two Sum II - Input array is sorted(兩數之和 II - 輸入有序數組)

這道題是LeetCode裏的第167道題。 題目描述: 給定一個已按照升序排列 的有序數組,找到兩個數使得它們相加之和等於目標數。 函數應該返回這兩個下標值 index1 和 index2,其中 index1 必須小於 index2。

原创 【LeetCode】Majority Element(求衆數)

這道題是LeetCode裏的第169道題。 題目描述: 給定一個大小爲 n 的數組,找到其中的衆數。衆數是指在數組中出現次數大於 ⌊ n/2 ⌋ 的元素。 你可以假設數組是非空的,並且給定的數組總是存在衆數。 示例 1: 輸入: [3