原创 【Leetcode】311. Sparse Matrix Multiplication

題目地址: https://leetcode.com/problems/sparse-matrix-multiplication/ 給定兩個稀疏矩陣AAA和BBB,求它們的乘積。題目保證AAA和BBB可乘。 法1:遍歷AAA的第i

原创 【Lintcode】987. Binary Number with Alternating Bits

題目地址: https://www.lintcode.com/problem/binary-number-with-alternating-bits/description 給定一個整數nnn,判斷其二進制表示中是否是000和11

原创 【Leetcode】540. Single Element in a Sorted Array

題目地址: https://leetcode.com/problems/single-element-in-a-sorted-array/ 給定一個從小到大排好序的數組AAA,除了其中一個數字只出現了一次外,每個數字都出現了兩次,

原创 【Lintcode】142. O(1) Check Power of 2

題目地址: https://www.lintcode.com/problem/o1-check-power-of-2/description 給定一個數,要求O(2)O(2)O(2)的時間判斷其是否爲222的冪次。只需看其二進制表

原创 【Lintcode】1320. Contains Duplicate

題目地址: https://www.lintcode.com/problem/contains-duplicate/description 給定一個數組,判斷其中是否有重複。用哈希表去重後看一下size和原數組長度是否相等即可,若

原创 【Lintcode】1013. Unique Morse Code Words

題目地址: https://www.lintcode.com/problem/unique-morse-code-words/description 參考https://blog.csdn.net/qq_46105170/arti

原创 【Lintcode】179. Update Bits

題目地址: https://www.lintcode.com/problem/update-bits/description 給定兩個323232位整數nnn和mmm,再給定兩個取值在0∼310\sim 310∼31的兩個整數ii

原创 【Leetcode】408. Valid Word Abbreviation

題目地址: https://leetcode.com/problems/valid-word-abbreviation/ 參考https://blog.csdn.net/qq_46105170/article/details/10

原创 【Leetcode】1426. Counting Elements

題目地址: https://leetcode.com/problems/counting-elements/ 給定一個數組,數一下有多少個數滿足其加一後也存在於數組中。用哈希表存一下即可。代碼如下: import java.uti

原创 【Leetcode】821. Shortest Distance to a Character

題目地址: https://leetcode.com/problems/shortest-distance-to-a-character/ 給定一個字符串sss和一個sss中字母ccc,要求返回一個數組AAA,其中A[i]A[i]

原创 【Lintcode】1332. Number of 1 Bits

題目地址: https://www.lintcode.com/problem/number-of-1-bits/description 給定一個數nnn,求其二進制表示中111的個數。可以用lowbit解決。其中lowbit(x)

原创 【Lintcode】365. Count 1 in Binary

題目地址: https://www.lintcode.com/problem/count-1-in-binary/description 給定一個323232位整數,求其二進制表示中111的個數。可以用lowbit解決。其中low

原创 【Lintcode】1495. Leaf-Similar Trees

題目地址: https://www.lintcode.com/problem/leaf-similar-trees/description 定義一棵二叉樹的”樹葉序列“,爲其所有葉子從左到右排列所成的序列。兩個葉子xxx和yyy,

原创 【Leetcode】1085. Sum of Digits in the Minimum Number

題目地址: https://leetcode.com/problems/sum-of-digits-in-the-minimum-number/ 給定一個數組,如果其最小值各個位數之和爲偶數則返回111,否則返回000。代碼如下:

原创 【Leetcode】1165. Single-Row Keyboard

題目地址: https://leetcode.com/problems/single-row-keyboard/ 給定一個字符串含262626個英文小寫字母,想象其爲鍵盤,起初手指在位置000(也就是鍵盤的第一個字符處),再給定一