Implement Stack using Queues
Implement Stack using QueuesImplement the following operations of a stack using queues. push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top elem
Implement Stack using QueuesImplement the following operations of a stack using queues. push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top elem
Contains Duplicate IIGiven an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between
Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false
Reverse Linked ListReverse a singly linked list. 提示 解題應用 LinkedList Pointer Default:12345678910/** * Definition for singly-linked list. * type ListNode struct { * Val int * Nex
Isomorphic StringsGiven two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be repla
Count PrimesCount the number of prime numbers less than a non-negative number, n. 提示 解題應用 HashTable Array Math 規律觀查 Default:123func countPrimes(n int) int {} 解答思路:非常典型的空間換取時間,因為
Remove Linked List ElementsRemove all elements from a linked list of integers that have value val. Example:12Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2
Happy NumberWrite an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of t
House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that a
Rotate ArrayRotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note: Try to come up as many solutions a
Factorial Trailing ZeroesGiven an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 提示 解題應用 Math 觀查規律 Default:123func trai
Excel Sheet Column NumberRelated to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example:1234567A -> 1B -> 2C
Majority ElementGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the major
Excel Sheet Column TitleGiven a positive integer, return its corresponding column title as appear in an Excel sheet. For Example:12345671 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB
Single NumberGiven an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without
Valid PalindromeGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example:12"A man, a plan, a canal: Panama" is a palindrome.
Best Time to Buy and Sell StockSay you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and
Pascal’s Triangle IIGiven an index k, return the kth row of the Pascal’s triangle. For example, given k = 3,Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space?
Pascal’s TriangleGiven numRows, generate the first numRows of Pascal’s triangle. For example:Given numRows = 5, Return 1234567[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]] 提示 解題應用 A