Move Zeroes
Move ZeroesGiven an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For example:1Given nums = [0, 1, 0, 3, 12], after call
Move ZeroesGiven an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For example:1Given nums = [0, 1, 0, 3, 12], after call
Missing NumberGiven an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. For example:1Given nums = [0, 1, 3] return 2. Note: Your algorithm sh
Ugly NumberWrite a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ug
Add DigitsGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example:1Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has onl
Binary Tree PathsGiven a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 12345 1 / \2 3 \ 5 All root-to-leaf paths are: 1["1->2->5",
Palindrome Linked ListGiven two strings s and t, write a function to determine if t is an anagram of s. For example:12s = "anagram", t = "nagaram", return true.s = "rat"
Palindrome Linked ListGiven a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 提示 解題應用 LinkedList Pointer Default:12345678910/**
Implement Queue using StacksImplement the following operations of a queue using stacks. push(x) – Push element x to the back of queue. pop() – Removes the element from in front of queue. peek() – Ge
Power of TwoGiven an integer, write a function to determine if it is a power of two. 提示 解題應用 Math 規律觀查 BitManipulation AND Default:123func isPowerOfTwo(n int) bool { } 解答思路:一
Invert Binary TreeInvert a binary tree. 12345 4 / \ 2 7 / \ / \1 3 6 9 to 12345 4 / \ 7 2 / \ / \9 6 3 1 提示 解題應用 Tree 樹的遍歷方式 Default:1234567891011/** *
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