![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
laicode
betty1121
这个作者很懒,什么都没留下…
展开
-
306. Check If Linked List Is Palindrome
Given a linked list, check whether it is a palindrome. Examples: Input: 1 -> 2 -> 3 -> 2 -> 1 -> null output: true. Input: 1 -> 2-> 3-> null output: false. Requirements: Space complexity must be O(1) 思路:找到中点,在reverse...原创 2021-07-14 16:53:19 · 145 阅读 · 0 评论 -
66. All Valid Permutations Of Parentheses I
Given N pairs of parentheses “()”, return a list with all the valid permutations. Assumptions N > 0 Examples N = 1, all valid permutations are ["()"] N = 3, all valid permutations are ["((()))", "(()())", "(())()", "()(())", "()()()"] 思路:先有左括号,才有右括号原创 2021-07-01 09:05:08 · 169 阅读 · 0 评论 -
64. All Permutations I----DFS
Given a string with no duplicate characters, return a list with all permutations of the characters. Assume that input string is not null. Examples Set = “abc”, all permutations are [“abc”, “acb”, “bac”, “bca”, “cab”, “cba”] Set = "", all permutations a原创 2021-06-30 05:29:39 · 197 阅读 · 0 评论 -
25. K Smallest In Unsorted Array
Find the K smallest numbers in an unsorted integer array A. The returned numbers should be in ascending order. Assumptions A is notnull K is >= 0 and smaller than or equal to size of A Return an array with size K containing the K smallest numbers i.原创 2021-06-30 03:12:38 · 135 阅读 · 0 评论 -
Rainbow Sort
Given an array of balls, where the color of the balls can only be Red, Green or Blue, sort the balls such that all the Red balls are grouped on the left side, all the Green balls are grouped in the middle and all the Blue balls are grouped on the right sid原创 2021-06-29 09:57:36 · 159 阅读 · 0 评论 -
Quick Sort
Given an array of integers, sort the elements in the array in ascending order. The quicksort algorithm should be used to solve this problem. Examples {1} is sorted to {1} {1, 2, 3} is sorted to {1, 2, 3} {3, 2, 1} is sorted to {1, 2, 3} {4, 2, -3, 6,.原创 2021-06-28 12:54:45 · 107 阅读 · 0 评论 -
548. Bounded Random Number
Write a function that returns a random number within the range of [a, b] with equal probabilities. Note: you can use Java’s Random class. class Solution { public int random(int a, int b) { Random rand = new Random(); int i = a + rand.ne原创 2021-06-26 07:11:39 · 152 阅读 · 0 评论 -
552. Sum of Numbers in a Stack
Calculate the sum of all numbers in a Stack. Assumption: The Stack is not null or empty. Example: Stack contains 7,5,3,0 Answer: 15 class Solution { public int sumOfStack(Deque<Integer> stack) { int sum = stack.pop(); while (!s原创 2021-06-26 07:07:56 · 148 阅读 · 0 评论 -
551. Maximum Number in a Queue
Given a queue of integers, find the maximum number in it. Assumption: the queue is not null or empty. Example: Queue contains 5,8,3,2,7 Answer: 8. class Solution { public int maxInQueue(Queue<Integer> queue) { int max = queue.poll();原创 2021-06-26 07:03:00 · 86 阅读 · 0 评论