这是我的力扣刷题记录,每天N题!
Easy
1 Two Sum
Description
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example
1 | Given nums = [2, 7, 11, 15], target = 9. |
Solution
1 | class Solution: |
771 Jewels and Stones
Description
You’re given strings J
representing the types of stones that are jewels, and S
representing the stones you have. Each character in S
is a type of stone you have. You want to know how many of the stones you have are also jewels.
The letters in J
are guaranteed distinct, and all characters in J
and S
are letters. Letters are case sensitive, so "a"
is considered a different type of stone from "A"
.
Examples
1 | Input: J = "aA", S = "aAAbbbb" |
Note
S
andJ
will consist of letters and have length at most 50.- The characters in
J
are distinct.
Solution
我的第一反应: 40ms
1 | class Solution: |
我觉得好的答案: 36ms
1 | class Solution: |
938 Range Sum of BST
Description
Given the root
node of a binary search tree, return the sum of values of all nodes with value between L
and R
(inclusive).
The binary search tree is guaranteed to have unique values.
Examples
1 | Input: root = [10,5,15,3,7,null,18], L = 7, R = 15 |
Note
- The number of nodes in the tree is at most
10000
. - The final answer is guaranteed to be less than
2^31
.
Solution
我的第一反应:232ms
1 |
|
我觉得比较好的答案: