記錄: 2017/2
Valid Perfect Square
Valid Perfect SquareGiven a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1:12
Sum of Two Integers
Sum of Two IntegersCalculate the sum of two integers a and b, but you are not allowed to use the operator + and -. For Example:1Given a = 1 and b = 2, return 3. 提示 解題應用 BitManipulation XOR,AND
Reverse Vowels of a String
Reverse Vowels of a StringWrite a function that takes a string as input and reverse only the vowels of a string. Example1:1Given s = "hello", return "holle". Example 2:1Given s =
Ransom Note
Ransom NoteGiven an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the ma
Intersection of Two Arrays
Intersection of Two ArraysGiven two arrays, write a function to compute their intersection. ###For Example: 1Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result
Intersection of Two Arrays II
Intersection of Two Arrays IIGiven two arrays, write a function to compute their intersection. For Example:1Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the resul
First Unique Character in a String
First Unique Character in a StringGiven a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. For Examples:12345s = "leetcode"return
Reverse String
Reverse StringWrite a function that takes a string as input and returns the string reversed. For Example:1Given s = "hello", return "olleh". 提示 解題應用 TwoPointers String D
Power of Four
Power of FourGiven an integer (signed 32 bits), write a function to check whether it is a power of 4. For Example:1Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve
Power of Three
Power of ThreeGiven an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? 提示 解題應用 Math 腦力激盪 Default:123func isP
Range Sum Query - Immutable
Range Sum Query - ImmutableGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. For Example:12345Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) ->
Word Pattern
Word PatternGiven a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in
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
Missing Number
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 Number
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 Digits
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 Paths
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 List
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 List
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 Stacks
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