原创 Remove Duplicates from Sorted Array
題目: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new le
原创 Search Insert Position
題目: Given a sorted array and a target value, return the index if the target is found. If not, return the index where i
原创 Count and Say
題目: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read
原创 Swap Nodes in Pairs
1、這種倒置的問題一半都要重新再選取一個listnode,然後再加上輔助的指針,cur,ret; 2、兩個結點兩個結點的倒置,間隔的方法爲next=ret->next->next; 題目: Given a linked list,
原创 Reverse Nodes in k-Group
題目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of
原创 Implement strStr()
1、要記住這種用雙重循環的查找方法; for(int i=0;i<=lengthA-lengthB;++i) { bool flag=true; for(int j=0;j<
原创 Next Permutation
題目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of number
原创 Generate Parentheses
題目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For exampl
原创 Search for a Range
題目: Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s
原创 Merge k Sorted Lists
1、新建一個結點ListNode *head=new ListNode(0); 2、privory—queue中可以按大小進行存儲的功能, priority_queue < Type, Container, Functional> 其
原创 Combination Sum II
題目: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the c
原创 Trapping Rain Water
題目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much wat
原创 Valid Sudoku
1、判斷數組中是否有重複的數,先令數組中的數爲0,然後當出現的時候+1,若再次出現的時候此數組中的數>0,表示重複出現,返回false; 題目: Determine if a Sudoku is valid, according to
原创 Longest Valid Parentheses
題目: Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) pare
原创 Multiply Strings
1、判斷乘數或者被乘數是不是負數,如果是的話去掉 ’ - ‘ if(num1[0]=='-' || num2[0]=='-') { if(num1[0]=='-') {