原创 leetcode (16) - 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Retu

原创 leetcode (9) - Palindrome Number 整數迴文

bool isPalindrome(int x) { bool is_flag=true; int reverse=0; int tmp=x; while(tmp) {

原创 leetcode (19) - Remove Nth Node From End of List

/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */

原创 leetcode (12) - INT TO ROMAN

Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 思路 首先,學習一下

原创 leetcode (13) - ROMAN TO INT

class Solution { public: int romanToInt(string s) { int ret = toNumber(s[0]); for (int i = 1; i < s

原创 leetcode (20) - Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid

原创 leetcode (6) - ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to displ

原创 leetcode (11) - Container With Most Water

題意:在一個座標系中,給出若干點,每個點做x軸的垂直線,然後求任何兩條線形成的容器中能盛下最多水的情況 分析: 1.  兩層for循環, O(n^2)的算法, leetcode不給通過===> time limited exceed 2

原创 linux中fork()函數詳解

 一、fork入門知識      一個進程,包括代碼、數據和分配給進程的資源。fork()函數通過系統調用創建一個與原來進程幾乎完全相同的進程,也就是兩個進程可以做完全相同的事,但如果初始參數或者傳入的變量不同,兩個進程也可以做不同的事。

原创 leetcode (8) - String to Integer

int myAtoi(char* str) { int length = strlen(str); int ret=0; int i=0; bool handle_flag=tru

原创 leetcode (14) - Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings. char* longestCommonPrefix(cha

原创 leetcode (17) - Letter Combinations of a Phone Number

因爲不知道digits的長度到底是多少,不可能寫無數個for循環來遍歷,只能使用遞歸。 void getLetterCom(char** res,char* digits,char* tmp,int index,char map[10]

原创 leetcode (5) - Longest Palindromic Substring 最長迴文子串

問題描述 迴文串是指這個字符串無論從左讀還是從右讀,所讀的順序是一樣的;簡而言之,迴文串是左右對稱的。現在,對於一個給定的母串 abcdedcb 可以找出子串a, ded, cdedc, bcdecdb等均是迴文串;顯然,bcde

原创 leetcode (15) - 3sum

void sort(int *a, int left, int right) { if(left >= right) { return ; } int i = left; int j = right; int key =

原创 leetcode (18) - 4Sum

Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all uniqu