不会飞的章鱼

熟能生巧,勤能补拙,静能生慧;念念不忘,必有回响。

题目

LeetCode
LeetCode-cn

Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Example 1:
Input: nums = [1,3,5,6], target = 5
Output: 2

Example 2:
Input: nums = [1,3,5,6], target = 2
Output: 1

Example 3:
Input: nums = [1,3,5,6], target = 7
Output: 4

Example 4:
Input: nums = [1,3,5,6], target = 0
Output: 0

Example 5:
Input: nums = [1], target = 0
Output: 0

Constraints:
1 <= nums.length <= 104
-104 <= nums[i] <= 104
nums contains distinct values sorted in ascending order.
-104 <= target <= 104

题解

阅读全文 »

题目

LeetCode
LeetCode-cn

Given an array nums and a value val, remove all instances of that value in-place and return the new length.

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

The order of elements can be changed. It doesn’t matter what you leave beyond the new length.

阅读全文 »

题目

Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

Clarification:

阅读全文 »

题目

LeetCode
LeetCode-cn

Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Example 1:

Input: l1 = [1,2,4], l2 = [1,3,4]
Output: [1,1,2,3,4,4]

Example 2:

Input: l1 = [], l2 = []
Output: []

Example 3:

Input: l1 = [], l2 = [0]
Output: [0]


Constraints:
The number of nodes in both lists is in the range [0, 50].
-100 <= Node.val <= 100
Both l1 and l2 are sorted in non-decreasing order.

题解

阅读全文 »

《武林高手在校园》这本穿越小说我高中&大学时读了很多遍,也算是我读的第一本穿越小说,有一处印象比较深的情节,在此记录并抒发一下自己的感受。

内容应该在73-74节之间,当时油老鼠和林逸飞在街上走着,突然碰到一个人骑自行车钱包掉了出来,立马有人过来说见者有份,要平分赃款,而林逸飞早已识破骗局,于是油老鼠也跟着走了,并说了一句“可恶的河南人”,而林逸飞就说出了我印象最深的话: 林逸飞叹息道:“哪个地方都有好人,都会有骗子,你这么一棒子把人打死,难道不嫌太武断了吗?”

为什么我会对这句话印象极其深刻呢?——因为我见过太多的地域歧视。

上大学那会,我的本科舍友们偶尔会在宿舍关灯后还是唠嗑,这时候我就会闭嘴,因为话题真的很无语,比如——他们一直认为四川人的个子都很矮(我只想说如果都很矮那难道像CBA这种篮球比赛四川队都垫底吗?);偷井盖子的都是河南人;广东人做的东西不要吃;….等等这种带着地域的偏见。

然而,当我毕业后,在成都拿了一家互联网公司的offer后,我发现四川当地人并不矮,地铁上、公交车上到处都是高个子;我在部门认识的河南同事都非常乐于助人,有时会停下手里的活帮我来看代码问题;广东的肠粉路边摊到处都是…所以,我学会了怀疑别人说的话,同时也建立了一个前提:哪个地方都有好人,都会有骗子,不能因为这地方出现了这件事情,就把这个地方的人一棍子打死。

阅读全文 »

题目

LeetCode
LeetCode-cn

Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string “”.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Example 1:

Input: strs = ["flower","flow","flight"]
Output: "fl"
Example 2:

Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.


Constraints:
0 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i] consists of only lower-case English letters.
阅读全文 »

题目

LeetCode
力扣

题解

先维护一个map,用于建立罗马数字和整数的关系,接着挨个破译即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//Go
func romanToInt(s string) int {
var charToIntMap = make(map[byte]int, 8)
charToIntMap['I'] = 1
charToIntMap['V'] = 5
charToIntMap['X'] = 10
charToIntMap['L'] = 50
charToIntMap['C'] = 100
charToIntMap['D'] = 500
charToIntMap['M'] = 1000
sum := 0
for i:= 0; i < len(s); i++ {
switch s[i] {
case 'I':
if i + 1 < len(s) && (s[i+1] == 'V' || s[i+1] == 'X') {
sum -= charToIntMap[s[i]]
} else {
sum += charToIntMap[s[i]]
}
break

case 'X':
if i + 1 < len(s) && (s[i+1] == 'L' || s[i+1] == 'C') {
sum -= charToIntMap[s[i]]
} else {
sum += charToIntMap[s[i]]
}
break

case 'C':
if i + 1 < len(s) && (s[i+1] == 'D' || s[i+1] == 'M') {
sum -= charToIntMap[s[i]]
} else {
sum += charToIntMap[s[i]]
}
break

default:
sum += charToIntMap[s[i]]
}
}

return sum
}
阅读全文 »

半年前意外看到了阿里巴巴半霜大佬的Github个人界面,甚是喜欢,今天晚上我利用了一个半小时的时间查资料分析代码,,地址点这里

个人觉得一个好的Github页面应该包含以下内容:

  • 简短的个人介绍
  • 最近的学习情况和期待完成的事
  • 社交&其他技术网站链接
  • 常用的软件和编程语言
  • Github信息,包括star数、commit次数、PRs等
  • 项目列表

以上,是我完成这次个人README的动力。

最后我想说,前端还是很有趣的,有空一定要系统学习一下^_^

阅读全文 »

第3集剧情简介

周末跟完了《工作细胞 BLACK》的最新剧集,第三集的剧情给我留下了非常深刻的印象,因为它触碰到了我上小学和中学的知识禁区——性行为。

第3集的大致剧情是一群红细胞收到了比运输氧气更重要的任务,就是这具身体因生殖行为而进行兴奋状态,需要红细胞使阴茎中的海绵组织(海绵体)勃起,完成射精!

但结果非常不顺:刚开始红细胞排成一队进入海绵体,把螺旋动脉张开,血液进去,进入勃起状态,看似一切顺利

阅读全文 »