原创 leetcode:Add Two Numbers

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

原创 360:挑選鎮長

#include <iostream> #include <vector> using namespace std; int main() { int T, n, m, a, b, i, j, cnt; vector<

原创 leetcode:Factorial Trailing Zeroes

 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time co

原创 劍指offer:合併兩個排序的鏈表

#include <iostream> #include <stdio.h> #include <malloc.h> using namespace std; struct ListNode { int val; st

原创 leetcode:the skyline problem

class Solution { public: struct node { int x, heightIndex; bool leftOrRight; node(int _

原创 分解質因數

#include <iostream> #include <cmath> #include <cstdio> using namespace std; bool isPrime(int n) { for(int i = 2;

原创 leetcode:Container With Most Water

class Solution { public: int maxArea(vector<int>& height) { /*int i, j, mx = 0; for(i = 0; i <

原创 360:最後一個字符

 正在挑戰一個CrackMe的你,把需要填寫的前面幾位密碼都正確猜出了,可是這最後一位密碼,好像藏得有點深。 CrackMe的作者還挑釁般的在裏面藏了個.tar.gz文件,解壓縮出來,裏面寫道你要的最後一個字符就在下面這個字符串裏。

原创 劍指offer:包含min函數的棧

 題目描述:定義棧的數據結構,請在該類型中實現一個能夠得到棧最小元素的min函數 class Solution { public: stack<int> s, mn; void push(int value) {

原创 劍指offer:樹的子結構

題目描述:輸入兩顆二叉樹A,B,判斷B是不是A的子結構 /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right;

原创 劍指offer:棧的壓入、彈出序列

 題目描述: 輸入兩個整數序列,第一個序列表示棧的壓入順序,請判斷第二個序列是否爲該棧的彈出順序。假設壓入棧的所有數字均不相等。例如序列1,2,3,4,5是某棧的壓入順序,序列4,5,3,2,1是該壓棧序列對應的一個彈出序列,但4,3

原创 最少錢幣數

 這是一個古老而又經典的問題。用給定的幾種錢幣湊成某個錢數,一般而言有多種方式。例如:給定了6種錢幣面值 爲2、5、10、20、50、100,用來湊15元,可以用5個2元、1個5元,或者3個5元,或者1個5元、1個10元,等等。 顯然

原创 劍指offer:順時針打印矩陣

 題目描述: 輸入一個矩陣,按照從外向裏以順時針的順序依次打印出每一個數字,例如,如果輸入如下矩陣: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 則依次打印出數字1,2,3,4,8,12,16,15,

原创 leetcode:Longest Substring Without Repeating Characters

class Solution { public: int lengthOfLongestSubstring(string s) { int i, j, k, len, preLen = 0, maxLen

原创 劍指offer:字符串的排列

題目描述:輸入一個字符串,按字典序打印出該字符串中字符的所有排列。例如輸入字符串abc,則打印出由字符a,b,c所能排列出來的所有字符串abc,acb,bac,bca,cab和cba(結果請按字母順序輸出)。 輸入描述:輸入一個字符串,長