原创 【Leetcode】766. Toeplitz Matrix

題目地址: https://leetcode.com/problems/toeplitz-matrix/ 給定一個矩陣,如果其所有左上到右下的對角線上面的值都相同,則稱其爲Toeplitz矩陣。判斷一個矩陣是否是Toeplitz矩

原创 【Lintcode】807. Palindrome Number II

題目地址: https://www.lintcode.com/problem/palindrome-number-ii/description 給定一個非負整數,判斷其二進制表示是否迴文。直接算其二進制翻轉後的數,看一下是否與原數

原创 【Lintcode】491. Palindrome Number

題目地址: https://www.lintcode.com/problem/palindrome-number/description 給定一個正整數,判斷其是否迴文。直接計算其翻轉後是幾,然後比較一下是否相等即可。代碼如下:

原创 【Lintcode】756. Multiply Two Numbers

題目地址: https://www.lintcode.com/problem/multiply-two-numbers/description 給定兩個鏈表,表示十進制整數。求兩個數的乘積。直接解析出兩個整數然後相乘即可。代碼如下

原创 【Lintcode】943. Range Sum Query - Immutable

題目地址: https://www.lintcode.com/problem/range-sum-query-immutable/description 給定一個數組,要求實現一個數據結構,可以進行給定區間[i,j][i,j][i

原创 【Lintcode】989. Array Nesting

題目地址: https://www.lintcode.com/problem/array-nesting/description 給定一個長度爲NNN的數組AAA,內容是0∼N−10\sim N-10∼N−1(順序可能是亂的)。現

原创 【Lintcode】1685. The mazeIV

題目地址: https://www.lintcode.com/problem/the-mazeiv/description 給定一個二維矩陣迷宮,SSS代表起點,TTT代表終點,#\##代表牆壁,...代表空地,問從起點到終點最少

原创 【Lintcode】494. Implement Stack by Two Queues

題目地址: https://www.lintcode.com/problem/implement-stack-by-two-queues/description 用兩個隊列來實現棧。 開兩個隊列q1q_1q1​和q2q_2q2​,

原创 【Lintcode】613. High Five

題目地址: https://www.lintcode.com/problem/high-five/description 給定一個二維數組,每一行有兩個數,代表學生的id和其某門課分數。返回每個學生的最高的555門課的平均分。 用

原创 【Lintcode】897. Island City

題目地址: https://www.lintcode.com/problem/island-city/description 給定一個二維矩陣,裏面的數字都是000,111或者222。將111和222視爲等價,要求返回含222的連

原创 【Lintcode】495. Implement Stack

題目地址: https://www.lintcode.com/problem/implement-stack/description 實現棧。 可以用一個數組實現棧,另外用一個變量size來標記當前棧裏元素個數。如果在push的時

原创 【Leetcode】890. Find and Replace Pattern

題目地址: https://leetcode.com/problems/find-and-replace-pattern/ 給定一個字符串數組,再給定一個字符串ppp,返回數組中與ppp“模式一樣”的字符串。“模式一樣”意思是存在

原创 【Leetcode】243. Shortest Word Distance

題目地址: https://leetcode.com/problems/shortest-word-distance/ 給定一個字符串列表,再給定其中的兩個字符串,題目保證兩個字符串不等。求這兩個字符串在列表裏出現的位置的最小下標

原创 【Lintcode】932. Friends Within Three Jumps

題目地址: https://www.lintcode.com/problem/friends-within-three-jumps/description 給定兩個數組aaa和bbb,長度相等,代表人的編號,a[i]a[i]a[i

原创 【Lintcode】1533. N-ary Tree Level Order Traversal

題目地址: https://www.lintcode.com/problem/n-ary-tree-level-order-traversal/description 分層遍歷一棵多叉樹。題目中的list的第一個元素即爲樹根。藉助