算法
文章平均质量分 90
静心观复
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
排序-冒泡排序
有时数组的后部分可能已经有序,但前面还未完全排序。可以记录每轮遍历中最后一次交换的位置,这样在下一轮遍历时只需遍历到该位置即可,无需遍历整个数组。实现方法引入一个变量,记录最后一次交换的位置。在下一轮遍历时,只需遍历到之前的位置。示例代码int newn;newn = n;i++) {// 交换 arr[i] 和 arr[i + 1]冒泡排序是一种简单直观的排序算法,通过重复比较和交换相邻元素,将较大的元素逐步“冒泡”到数组的末端。原创 2024-12-23 10:19:42 · 1200 阅读 · 0 评论 -
快速排序算法
*快速排序(Quick Sort)**是一种基于分治法的高效排序算法,由C. A. R. Hoare于1960年提出。它的平均时间复杂度为O(n log n),在实际应用中,由于其优秀的性能和较高的效率,被认为是排序算法中的佼佼者。希望以上内容能够帮助您深入理解快速排序算法及其在力扣题目中的应用。如有疑问,欢迎继续提问!在LeetCode上,有多道题目涉及到快速排序或其应用。依此类推,最终序列有序。原创 2024-12-20 20:00:48 · 1822 阅读 · 0 评论 -
Linked List Cycle
Leetcode:141. Linked List CycleMethod1/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * ne...原创 2019-12-19 17:00:11 · 143 阅读 · 0 评论 -
Valid Parentheses
Leetcode:20.Valid Parenthesesclass Solution { private HashMap<Character,Character> hashmap; { hashmap = new HashMap(); hashmap.put(')','('); hashmap.put('}','{'); hash...原创 2019-12-10 13:39:55 · 125 阅读 · 0 评论 -
Remove Nth Node From End of List
Problem solving ideasFirst we will add a dummy node as an auxiliary, which is located at the head of the list. Dumb nodes are used to simplify some extreme cases, such as the list contains only one ...原创 2019-12-10 11:14:26 · 138 阅读 · 0 评论 -
Find the maximum element in an array which is first increasing and then decreasing
Examples :Input: arr[] = {1, 3, 50, 10, 9, 7, 6}Output: 50Method 1 (Linear Search)public class FindMaximum { static int findMaximum(int arr[], int low, int high) { int max = arr[low];...原创 2019-12-06 14:28:34 · 268 阅读 · 0 评论 -
Ugly Number
leetcode(264. Ugly Number II)method 1(Use Dynamic Programming)public class UglyNumber{ public static int nthUglyNumber(int n) { int[] dp = new int[n]; dp[0] = 1; int i...原创 2019-12-05 09:45:56 · 136 阅读 · 0 评论 -
Binary Tree Level Order Traversal
single line and multi line printpublic class LevelOrderTraversal { public static class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public...原创 2019-12-04 14:59:44 · 141 阅读 · 0 评论 -
Java Program for Fibonacci numbers
Use recursion Programmingclass Fibonacci { static int fib(int n) { if (n <= 1) return n; return fib(n-1) + fib(n-2); } } Use memory searchclass Fibonacci { ...原创 2019-11-14 14:05:46 · 152 阅读 · 0 评论 -
Fibonacci Sequence
overviewFibonacci numbers are used to create technical indicators using a mathematical sequence developed by the Italian mathematician, commonly referred to as “Fibonacci,” in the 13th century. The s...原创 2019-11-14 10:53:21 · 603 阅读 · 0 评论
分享