随笔分类 -  软件工程相关 / 数据结构与算法

摘要:描述 You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, 阅读全文
posted @ 2022-07-22 16:44 IslandZzzz 阅读(32) 评论(0) 推荐(0) 编辑
摘要:描述 Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted or 阅读全文
posted @ 2022-07-22 10:53 IslandZzzz 阅读(23) 评论(0) 推荐(0) 编辑
摘要:描述 You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in 阅读全文
posted @ 2022-07-19 23:59 IslandZzzz 阅读(18) 评论(0) 推荐(0) 编辑
摘要:描述 Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors 阅读全文
posted @ 2022-07-19 22:35 IslandZzzz 阅读(17) 评论(0) 推荐(0) 编辑
摘要:// 递归处理, 利用函数作用域操作当前节点和当前节点的下一个节点 const reverseList = head => { if (head == null || head.next == null) return head const end = reverseList(head.next) 阅读全文
posted @ 2022-07-19 14:36 IslandZzzz 阅读(13) 评论(0) 推荐(0) 编辑
摘要:题目描述 Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. 阅读全文
posted @ 2022-07-19 11:27 IslandZzzz 阅读(14) 评论(0) 推荐(0) 编辑
摘要:题目描述 Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The r 阅读全文
posted @ 2022-07-18 16:25 IslandZzzz 阅读(18) 评论(0) 推荐(0) 编辑
摘要:题目描述 Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do t 阅读全文
posted @ 2022-07-17 01:42 IslandZzzz 阅读(24) 评论(0) 推荐(0) 编辑
摘要:1 数组实现 维护一个数组,总是记录无重复子串; 维护一个变量,总是记录当前无重复子串的长度中较长的那个 有重复,就删除当前记录重复子串中导致重复的部分子串0~start。 每次遍历在记录长度时,和当前记录值比较,取较大的那个。 最终记录的是最长子串长度 const lengthOfLongestS 阅读全文
posted @ 2022-06-29 16:28 IslandZzzz 阅读(43) 评论(0) 推荐(0) 编辑
摘要:// 给一个数组和一个值,获取数组元素之和为这个值的组合 function getIndex(arr,v){ if(!Array.isArray(arr)){ throw 'TypeError' } const map = arr.reduce((total, cur, index) => Obje 阅读全文
posted @ 2022-06-28 18:49 IslandZzzz 阅读(20) 评论(0) 推荐(0) 编辑
摘要:const isSortable = v => { if (!Array.isArray(v) || v.length < 2) { throw 'Not an array or length less than 1' } } /** * 冒泡 * 相邻比较,第一层表示趟数,第二层表示当前趟需要比较 阅读全文
posted @ 2022-06-28 16:51 IslandZzzz 阅读(23) 评论(0) 推荐(0) 编辑
摘要:冒泡排序与优化 冒泡排序是一种简单经典的排序,通过比较相邻位置,在第n趟比较结束之后即可确定第n大/小的值,比较结束后全部元素按照顺序排列 时间复杂度 平均时间复杂度为O(n²),最优为O(n),属于性能比较差的排序方式 空间复杂度 由于只在数组里面进行元素位置的交换,属于原地排序,不分配额外内存空 阅读全文
posted @ 2022-04-11 19:15 IslandZzzz 阅读(256) 评论(0) 推荐(0) 编辑
摘要:leetcode 1 两数之和 O(n)时间复杂度实现 描述: 输入:nums = [2,7,11,15], target = 9 输出:[0,1] 解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1]。 /** 思路: map实现 一个数为a,另一个数即为diff = s 阅读全文
posted @ 2022-04-09 02:35 IslandZzzz 阅读(61) 评论(0) 推荐(0) 编辑
摘要:/** 输入: const systems = ["mac", "windows"] const prices = ["5000","10000"] const storages = ["512g", "1T"] 返回: [ ["mac", "$5000", "512g"], ["mac", 阅读全文
posted @ 2022-03-29 01:53 IslandZzzz 阅读(59) 评论(0) 推荐(0) 编辑
摘要:Code: package dataStucture2.stackandqueue; /** * 循环队列 * * @param <E> */ public class MyLoopQueue<E> implements Queue<E> { /* * 成员变量:泛型数组、两个指向变量、循环队列个数 阅读全文
posted @ 2019-04-11 13:38 IslandZzzz 阅读(263) 评论(0) 推荐(0) 编辑
摘要:实现动态泛型数组: package dataStucture2.array; /** * 动态泛型数组 * * @author 李腾 * * @param <E> */ public class MyDynamicArray<E> { /* * MyArray对象应当含有的成员属性: * 1 应当含 阅读全文
posted @ 2019-04-07 10:20 IslandZzzz 阅读(273) 评论(0) 推荐(0) 编辑
摘要:package com.lt.datastructure.MaxHeap; import java.util.LinkedList; import java.util.List; import java.util.TreeMap; import com.lt.datastructure.Queue. 阅读全文
posted @ 2018-12-04 23:20 IslandZzzz 阅读(570) 评论(0) 推荐(0) 编辑
摘要:复杂度: 基于堆实现优先队列: package com.lt.datastructure.MaxHeap; import com.lt.datastructure.Queue.Queue; /** * 堆实现优先队列 */ public class PriorityQueue<E extends C 阅读全文
posted @ 2018-12-04 19:38 IslandZzzz 阅读(191) 评论(0) 推荐(0) 编辑
摘要:用二叉树实现堆: 用数组存储二叉堆: 基于数组实现二叉堆: package com.lt.datastructure.MaxHeap; public class MaxHeap<E extends Comparable<E>> { private Array1<E> data; public Max 阅读全文
posted @ 2018-12-02 09:56 IslandZzzz 阅读(228) 评论(0) 推荐(0) 编辑
摘要:LeetCode 349: package com.lt.datastructure.Set; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.LinkedList; import java.u 阅读全文
posted @ 2018-11-27 21:27 IslandZzzz 阅读(153) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示