This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
struct node { | |
int index; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int removeDuplicates(int A[], int n) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int newLength = 0; | |
if(n == 0) { | |
return newLength; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// Divide_Two_Integers | |
// | |
// Created by Zhoutuo Yang on 2/15/13. | |
// Copyright (c) 2013 Zhoutuo Yang. All rights reserved. | |
// | |
#include <iostream> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> plusOne(vector<int> &digits) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
for(int i = 0; i < digits.size() / 2; ++i) { | |
swap(digits[i], digits[digits.size() - i - 1]); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
void nextPermutation(vector<int> &num) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
bool found = false; | |
int left = -1; | |
int right = num.size(); | |
for(int i = num.size() - 1; i >= 0; --i) { | |
int cur = num[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int searchInsert(int A[], int n, int target) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int low = 0; | |
int high = n; | |
while(low < high) { | |
int middle = low + (high - low) / 2; | |
if(A[middle] == target) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> searchRange(int A[], int n, int target) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int low = low_bound(A, n, target); | |
int high = high_bound(A, n, target); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<vector<int> > combinationSum(vector<int> &candidates, int target) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
sort(candidates.begin(), candidates.end()); | |
vector<int> curResult; | |
vector<vector<int> > results; | |
solve(candidates, target, results, 0, curResult); | |
return results; |