This file contains hidden or 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: | |
bool searchMatrix(vector<vector<int> > &matrix, int target) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
//search row first | |
int low = 0; | |
int high = matrix.size(); |
This file contains hidden or 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 binary tree | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { |
This file contains hidden or 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 binary tree | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { |
This file contains hidden or 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; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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; |