原创 [C++]LeetCode: 111 Spiral Matrix II (螺旋寫入矩陣)

題目: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Give

原创 [C++]LeetCode: 115 Permutations (求一組數的全排列)

題目: Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutati

原创 [C++]LeetCode: 113 Word Break II (DP && Backtacking) 求解拆分組合

題目: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a vali

原创 [C++]LeetCode: 112 Word Break(DP)

題目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence o

原创 [C++]LeetCode: 108 Add Two Numbers (反序鏈表求和)

題目: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and

原创 [C++]LeetCode: 99 Longest Palindromic Substring (最長迴文子串)

題目:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 100

原创 [C++]LeetCode: 101 Binary Tree Zigzag Level Order Traversal

題目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then r

原创 [C++]LeetCode: 98 Evaluate Reverse Polish Notation

題目: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each

原创 [C++]LeetCode: 109 Swap Nodes in Pairs (交換相鄰節點位置)

題目: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should

原创 [C++]LeetCode: 103 Jump Game (局部最優和全局最優法)

題目: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each eleme

原创 [C++]LeetCode: 102 Flatten Binary Tree to Linked List (二叉樹轉前序鏈表)

題目: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2

原创 [C++]LeetCode: 100 Convert Sorted Array to Binary Search Tree (AVL樹)

題目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 思路:給出一個排序的數組,如何構造

原创 [C++]LeetCode: 106 Convert Sorted List to Binary Search Tree (有序鏈表轉AVL樹)

題目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 思路: 這

原创 [C++]LeetCode: 107 Reverse Words in a String (2014騰訊實習筆試題)

題目: Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue i

原创 [C++]LeetCode: 105 Longest Substring Without Repeating Characters

題目: Given a string, find the length of the longest substring without repeating characters. For example, the longest su