![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
Jie_newbie
这个作者很懒,什么都没留下…
展开
-
打开转盘锁
问题描述你有一个带有四个圆形拨轮的转盘锁。每个拨轮都有10个数字: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’ 。每个拨轮可以自由旋转:例如把 ‘9’ 变为 ‘0’,‘0’ 变为 ‘9’ 。每次旋转都只能旋转一个拨轮的一位数字。锁的初始数字为 ‘0000’ ,一个代表四个拨轮的数字的字符串。列表 deadends 包含了一组死亡数字,一...原创 2019-11-22 00:06:08 · 142 阅读 · 0 评论 -
二叉树相关的算法(一)
二叉树的定义// javapublic class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}把字符串转为二叉树, 字符串形式[1,2,3]public static TreeNode stringToTreeNode(Str...原创 2019-11-17 23:10:12 · 110 阅读 · 0 评论 -
Decode Ways
问题描述A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1‘B’ -> 2…‘Z’ -> 26Given a non-empty string containing only digits, determine...原创 2019-11-16 22:30:39 · 52 阅读 · 0 评论 -
最长公共前缀
问题描述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 “”.Example 1:Input: [“flower”,“flow”,“flight”]Outpu...原创 2019-11-15 23:23:45 · 86 阅读 · 0 评论 -
4Sum
问题描述Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum o...原创 2019-11-14 22:23:51 · 63 阅读 · 0 评论 -
接雨水
问题描述Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented by a...原创 2019-11-13 22:51:08 · 56 阅读 · 0 评论 -
简化路径
问题描述Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.In a UNIX-style file system, a period . refers to the current directory. Furtherm...原创 2019-11-12 22:31:02 · 113 阅读 · 0 评论 -
字符串的排列
问题描述给定两个字符串 s1 和 s2,写一个函数来判断 s2 是否包含 s1 的排列。换句话说,第一个字符串的排列之一是第二个字符串的子串。示例1:输入: s1 = "ab" s2 = "eidbaooo"输出: True解释: s2 包含 s1 的排列之一 ("ba").示例2:输入: s1= "ab" s2 = "eidboaoo"输出: False注意:输入的字符...原创 2019-11-11 22:17:13 · 119 阅读 · 0 评论 -
反转链表
问题描述反转一个单链表。比如,输入: 1->2->3->4->5->NULL,输出: 5->4->3->2->1->NULL。如下是链表节点的定义:/** * Java 定义 * public class ListNode { * int val; * ListNode next; * ListNo...原创 2019-11-10 14:06:07 · 61 阅读 · 0 评论 -
寻找两个有序数组的中位数
问题描述给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。你可以假设 nums1 和 nums2 不会同时为空。示例 1:nums1 = [1, 3]nums2 = [2]则中位数是 2.0示例 2:nums1 = [1, 2]nums2 = [3, 4]则中位数是...原创 2019-11-09 22:28:40 · 51 阅读 · 0 评论 -
两两交换链表中的节点
问题描述给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。示例:1->2->3->4, 你应该返回 2->1->4->3.解题思路:解决该问题可以通过两种方式: 一是交换相邻节点的值,二是改变next指针的方向。代码解法一递归 交换相邻节点的值public ListNo...原创 2019-11-08 22:05:46 · 59 阅读 · 0 评论 -
螺旋矩阵
问题描述给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。实例一:输入:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]输出: [1,2,3,6,9,8,7,4,5]实例二:输入:[[1, 2, 3, 4],[5, 6, 7, 8],[9,10,11,12]]输出: [1,2,3...原创 2019-11-07 23:15:20 · 111 阅读 · 0 评论 -
对角线遍历
@题目描述给定一个含有 M x N 个元素的矩阵(M 行,N 列),请以对角线遍历的顺序返回这个矩阵中的所有元素,对角线遍历如下图所示。实例:输入:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]输出: [1,2,4,7,5,3,6,8,9]说明:给定矩阵中的元素总数不会超过 100000 。解题思路在遍历二维数组中主要有两个方向变换...原创 2019-11-06 23:46:09 · 361 阅读 · 0 评论