原创 劍指offer之面試題14——調整數組順序使奇數位於偶數前面

題目: 輸入一個整數數組,實現一個函數來調整該數組中數字的順序,使得所有奇數位於數組的前半部分,所有偶數位於數組的後半部分。 代碼: 方法一——只完成基本功能的解法,冒泡排序的思路,複雜度O(n^2) void adjustoddeve

原创 劍指offer面試題13——在O(1)時間刪除鏈表結點

題目: 給定單向鏈表的頭指針和一個結點指針,定義一個函數在 O(1)時間刪除該結點。鏈表結點與函數的定義如下: 代碼: void DeleteNode(ListNode** pListHead,ListNode* pToBeDele

原创 Leetcode之Path with Maximum Gold

題目: In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that ce

原创 劍指offer第12題——打印1到最大的n位數

題目: 題目:輸入數字n,按順序打印出從1最大的n位十進制數。比如輸入3,則打印出1、2、3一直到最大的3位數即999。 代碼: 方法一——使用字符串模擬數字,解決大數問題: string deletezero(string s) {

原创 Leetcode之Hamming Distance

題目: The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

原创 Leetcode之Smallest Good Base

題目: For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1. Now given a string representing n

原创 Leetcode之Additive Number

題目: Additive number is a string whose digits can form additive sequence. A valid additive sequence should contain at le

原创 Leetcode之Find All Numbers Disappeared in an Array

題目: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear onc

原创 Leetcode之Bulls and Cows

題目: You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to

原创 Leetcode之Burst Balloons

題目: Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You

原创 Leetcode之Delete Node in a BST

題目: Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node

原创 Leetcode之Binary Tree Cameras

題目: Given a binary tree, we install cameras on the nodes of the tree.  Each camera at a node can monitor its parent, it

原创 Leetcode之 Nim Game

題目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of y

原创 Leetcode之Game of Life

題目: According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised

原创 Leetcode之Decode String

題目: Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_stri