原创 Leetcode #258 Add Digits

class Solution { public: int addDigits(int num) { int sum = 0; while(num > 0) { sum +=

原创 Leetcode #191 Number of 1 Bits

Question: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as th

原创 Leetcode #83 Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2

原创 Leetcode #292 Nim Game

class Solution { public: bool canWinNim(int n) { return !(n % 4 == 0); } };只要n-1 或者 n-2 或者 n-3之後是4的倍數,就

原创 Leetcode #242 Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = "anagram", t = "nag

原创 Leetcode #226 Invert Binary Tree

TreeNode* invertTree(TreeNode* root) { if(!root) return NULL; TreeNode* temp; temp = root->left; root->left = ro

原创 Leetcode #101 Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this bina

原创 Leetcode #171 Excel Sheet Column Number

Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its correspondi

原创 Leetcode #217 Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value ap

原创 Leetcode #283 Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the no

原创 Leetcode #169 Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2

原创 Leetcode #100 Same tree

Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if

原创 Is It A Tree?,判斷是否是一棵樹。(題目來源:九度OJ 1481,2012年北京大學計算機研究生機試真題)

題目描述: A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more node

原创 Leetcode #237 Delete Node in a Linked List

Delete Node in a Linked List My Submissions Question Total Accepted: 46246 Total Submissions: 104863 Difficulty

原创 Leetcode #104 Maximum Depth of Binary Tree

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *