原创 leetcode 110.Balanced Binary Tree

題目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is define

原创 搜狗2016研發工程師筆試(矩陣元素相乘)

題目: 思路: 將A[i][j]所在行除了A[i][j]元素的其餘元素之積與A[i][j]所在列除了A[i][j]元素的其餘元素之積相乘, 其中A[i][j]所在行除了A[i][j]元素的其餘元素之積爲A[i][j]後面元素之積與前面

原创 leetcode 101. Symmetric Tree

題目: 要求判斷一棵二叉樹是否對稱 思路:採用遞歸的辦法,直接比較對稱位置,即將left的left和right的right比較,left的right和right的left比較。時間複雜度爲O(n)。 代碼AC: 點

原创 leetcode 69. Sqrt(x)

Implement int sqrt(int x). Compute and return the square root of x. 如果採用暴力破解法,從 0 到 x/2之間依次遍歷,但是時間太慢,故選擇考慮二分法。

原创 leetcode 125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For exam

原创 leetcode 104. Maximum Depth of Binary Tree

題目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from t

原创 位運算基本操作總結

一:位運算基本操作知識點 1. 左移操作 a << b 將A的二進制表示的每一位向左移B位,左邊超出的位截掉,右邊不足的位補0 A = 1100  B = 2 A << B = 110000 每左移一位,數值乘以2。 2

原创 leetcode 107. Binary Tree Level Order Traversal II Add to List

題目: 要求從左往右,從下往上層次遍歷二叉樹。 代碼AC: 點贊 收藏 分享 文章舉報 hui1140621618 發佈了36 篇原創文章 · 獲贊 1 · 訪問量

原创 leetcode 88. Merge Sorted Array

題目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume

原创 快速冪

快速冪的目的: 做到快速求冪。假設我們要求a^b,按照樸素算法就是把a連乘b次,這樣一來時間複雜度是O(b)也即是O(n)級別。如果n非常大時,就會超時。而快速冪的時間複雜度爲O(logn)。 快速冪的原理: 假設我們要求a^b,其實b

原创 leetcode 82. Remove Duplicates from Sorted List II

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

原创 二叉樹遍歷

二叉樹的前序遍歷:      1.訪問根節點      2.前序遍歷左子樹      3.前序遍歷右子樹  二叉樹的中序遍歷:      1.中序遍歷左子樹      2.訪問根節點      3.中序遍歷右子樹  二叉樹的後序遍歷:

原创 leetcode 136. Single Number

題目:Given an array of integers, every element appears twice except for one. Find that single one. 找到在數組中只出現過一次的數,要求線性時間

原创 leetcode 108. Convert Sorted Array to Binary Search Tree Add to List

題目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 給定一個遞增的數組,要求創建一棵二插

原创 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