
每天一道算法题
文章平均质量分 51
iamaline
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[python]矩阵按对角线打印
Description:将一个矩阵(二维数组)按对角线向右进行打印。(搜了一下发现好像是美团某次面试要求半小时手撕的题)Example:Input:[[1,2,3,4],[5,1,2,3],[9,5,1,2]]Output:[[4],[3, 3],[2, 2, 2],[1, 1, 1],[5, 5],[9]]思路: 考虑每条对角线开头元素的index(i,j)...原创 2018-09-18 23:18:46 · 4245 阅读 · 0 评论 -
[python]剑指Offer-替换空格
牛客OJ:替换空格Description:请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。思路一:新建字符串,依次遍历输入字符串,若为空格则替换后加入新字符串,若非空格则直接加入。# -*- coding:utf-8 -*-class Solution: ...原创 2019-03-14 10:38:55 · 322 阅读 · 0 评论 -
[python]剑指Offer-从尾到头打印链表
牛客OJ:从尾到头打印链表Description:输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。思路一:用一个list把链表中的元素依次压入,然后对链表进行翻转。注意:python中list.reverse()没有返回值,故不能直接return list.reverse();也不能令list2=list.reverse()再return list2。# -...原创 2019-03-15 20:40:37 · 766 阅读 · 0 评论 -
[python]Leetcode3-Longest Substring Without Repeating Characters
Description:Given a string, find the length of the longest substring without repeating characters.Example1:Input: “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Examp...原创 2019-03-13 09:43:48 · 141 阅读 · 0 评论 -
[python]剑指Offer-复杂链表的复制
Description:输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)练习地址:牛客OJ思路:整个复制过程分为三步代码:# -*- coding:utf-8 -*-# class RandomListNode:...原创 2018-09-20 17:48:02 · 457 阅读 · 0 评论 -
[python]Leetcode2-Add Two Numbers
Description:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two number...原创 2018-09-30 21:58:33 · 381 阅读 · 0 评论 -
[python]Leetcode1-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 ...原创 2018-09-30 16:33:20 · 177 阅读 · 0 评论 -
[python]Leetcode25-Reverse Nodes in k-Group
Description: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked li...原创 2018-09-06 23:16:50 · 566 阅读 · 0 评论 -
[python]剑指Offer-二维数组中的查找
牛客OJ:二维数组中的查找Description:在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。思路:由右上角至左下角进行查找;若当前元素值大于目标值,则向左继续查找;若当前元素值小于目标值,则向下继续查找;否则返回True;若到达...原创 2019-03-13 10:22:24 · 200 阅读 · 0 评论