原创 【Lintcode】892. Alien Dictionary

題目地址: https://www.lintcode.com/problem/alien-dictionary/description 給定一個字符串數組,在某種字典序下這個數組是有序的,要求求這個字典序並以字符串的形式返回。如果

原创 【Lintcode】383. Container With Most Water

題目地址: https://www.lintcode.com/problem/container-with-most-water/description 給定一個數組AAA,代表擋板的高度,選定兩個擋板,兩個擋板中間的區域可以看成

原创 【Leetcode】1392. Longest Happy Prefix

題目地址: https://leetcode.com/problems/longest-happy-prefix/ 給定一個字符串,其長度爲kkk的前綴和長度爲kkk後綴有可能相等,問最大的kkk對應的那個前綴是什麼。 題目本質上

原创 【Leetcode】867. Transpose Matrix

題目地址: https://leetcode.com/problems/transpose-matrix/ 給定一個矩陣,求其轉置。 注意,給出的矩陣未必是方陣,所以要另外開一個二維數組返回。代碼如下: public class

原创 【Lintcode】840. Range Sum Query - Mutable

題目地址: https://www.lintcode.com/problem/range-sum-query-mutable/description 給定一個數組,要求設計一個數據結構,支持區間和的查詢,以及單點修改。 樹狀數組(

原创 【Lintcode】993. Array Partition I

題目地址: https://www.lintcode.com/problem/array-partition-i/description 給定一個長度爲2n2n2n的數組AAA,要求將其分爲nnn個數對(ai,bi)(a_i,b_

原创 【Lintcode】1704. Range Sum of BST

題目地址: https://www.lintcode.com/problem/range-sum-of-bst/description 給定一棵BST,再給定區間[L,R][L,R][L,R],求BST中所有屬於這個區間的數字之和

原创 【Leetcode】28. Implement strStr()

題目地址: https://leetcode.com/problems/implement-strstr/ 給定兩個字符串,判斷第二個是否是第一個的子串,如果是則返回匹配的起始地址,否則返回−1-1−1。 法1:暴力法。直接枚舉所

原创 【Leetcode】422. Valid Word Square

題目地址: https://leetcode.com/problems/valid-word-square/ 給定一個字符串列表,判斷一下其作爲字符二維矩陣是否關於從左上到右下的對角線對稱。可以將每列的字符串求出來,然後和對應行的

原创 【Lintcode】1840. Matrix restoration

題目地址: https://www.lintcode.com/problem/matrix-restoration/description 給定某個二維數組的前綴和數組(對於二維數組AAA,其前綴和數組爲BBB,則B[i][j]=

原创 【Lintcode】924. Shortest Word Distance

題目地址: https://www.lintcode.com/problem/shortest-word-distance/description 給定一個字符串數組,再給定兩個單詞,求這兩個單詞在字符串中最小的下標距離(數組中可

原创 【Lintcode】371. Print Numbers by Recursion

題目地址: https://www.lintcode.com/problem/print-numbers-by-recursion/description 給定正整數NNN,返回從111開始數到NNN個999的所有數字。要求用遞歸

原创 【Lintcode】647. Find All Anagrams in a String

題目地址: https://www.lintcode.com/problem/find-all-anagrams-in-a-string/description 給定兩個字符串sss和ppp,如果ppp的某個排列能成爲sss的子串

原创 【Lintcode】128. Hash Function

題目地址: https://www.lintcode.com/problem/hash-function/description 給定一個字符串sss,給定一個數hash_sizehash\_sizehash_size定義其哈希函

原创 【Lintcode】1169. Permutation in String

題目地址: https://www.lintcode.com/problem/permutation-in-string/description 給定兩個字符串s1s_1s1​和s2s_2s2​,判斷將s1s_1s1​中的字符重排