4.15Leetcode日记

今天做了好几道字符串和链表的题
不得不说
Python做很多字符串的题,跟作弊一样快

1字符串的排列

Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of the second string.
这道题思路我也有,自己也能写,但是代码却不如别人的聪明,其实最简单的方法就是用区间字典的方式,每次移动字典发生一次变化,和s1进行对比,通过别人的代码看到了自己的不足。

2字符串相乘

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.
这道题跟两数相加(链表数相加)的逻辑非常相似,即通过整除取进位,通过取余取本位,不一样的是链表数相加进位最多为1,所以只需记录是否有进位即可。字符串相乘涉及到多次进位和进位大于1所以最好的方式是用空间换时间,用LIST进行记录。

3复原IP和排序列表

思路很简单,完全是考验人的递归能力,代码极多思路简单粗暴,所以我没有自己复现,有时间可以再做一次。

4.环形链表 II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.

Note: Do not modify the linked list.
非常好的一道题,考验了人的思维能力,明白快慢指针的原理很简单,不明白的话抓破脑袋也想不好,这道题我见过两次了,但是这次还是毫无头绪,说明我学习还不够扎实

猜你喜欢

转载自blog.csdn.net/qq_43100883/article/details/89314426