
算法 leetcode
文章平均质量分 70
wyj7260
这个作者很懒,什么都没留下…
展开
-
Leetcode Pascal's Triangle II
class Solution {public: vector getRow(int rowIndex) { vector result; int i = 0; int j = 0; if(rowIndex < 0) { return result; } result.原创 2014-10-05 22:04:47 · 976 阅读 · 0 评论 -
Leetcode Two Sum
struct Node{ int index; int value;};bool compare(Node a, Node b){ return a.value < b.value;}class Solution {public: vector twoSum(vector &numbers, int target) {原创 2014-10-05 20:26:34 · 927 阅读 · 0 评论 -
Leetcode Binary Tree Preorder Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2014-10-04 14:15:57 · 1210 阅读 · 0 评论 -
Leetcode Path Sum
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ /** * http原创 2014-10-07 22:49:33 · 1238 阅读 · 0 评论 -
Leetcode Best Time to Buy and Sell Stock III
/*** 题目:https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/* Say you have an array for which the ith element is the price of a given stock on day i.* Design an algorithm to find t原创 2014-10-07 09:44:23 · 1070 阅读 · 0 评论 -
Leetcode Best Time to Buy and Sell Stock II
/** * Say you have an array for which the ith element is the price of a given stock on day i. * Design an algorithm to find the maximum profit. You may complete as many transactions as you like *原创 2014-10-07 08:54:39 · 1434 阅读 · 0 评论 -
Leetcode Remove Duplicates from Sorted Array
class Solution {public: int removeDuplicates(int A[], int n) { int duplicate = 0; int i = 0; for(i = 0; i < n - 1; i++){ if(A[i] == A[i + 1]){ dupli原创 2014-10-05 20:28:56 · 959 阅读 · 0 评论 -
Surrounded Regions
/** * https://oj.leetcode.com/problems/surrounded-regions/ * 从四个边界的'O'出发,它们所能到达的'O'就是没有被包围的'O'。 * 所以,该题可以用BFS遍历或者DFS遍历。*/class Solution {public: void solve(vector> &board) { int row原创 2014-10-06 20:47:25 · 997 阅读 · 0 评论 -
Leetcode Single Number II
/**Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2014-10-04 13:20:53 · 854 阅读 · 0 评论 -
Leetcode Pascal's Triangle
class Solution {public: vector > generate(int numRows) { vector > result; vector innerResult; int i = 0; int j = 0; for(i = 0; i < numRows; i++){原创 2014-10-05 21:23:35 · 896 阅读 · 0 评论 -
Leetcode Plus One
//Given a non-negative number represented as an array of digits, plus one to the number.//The digits are stored such that the most significant digit is at the head of the list.//digits={9,9,9,原创 2014-10-06 12:27:04 · 1145 阅读 · 0 评论 -
Leetcode Linked List Cycle
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool hasCycl原创 2014-10-04 13:42:14 · 845 阅读 · 0 评论 -
Leetcode Candy
https://oj.leetcode.com/problems/candy/原创 2014-10-04 10:41:50 · 1112 阅读 · 0 评论 -
Leetcode Best Time to Buy and Sell Stock
/*** https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock/* Say you have an array for which the ith element is the price of a given stock on day i.* If you were only permitted to comple原创 2014-10-06 21:41:17 · 1063 阅读 · 0 评论 -
Leetcode Symmetric Tree
非递归解法/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class原创 2014-10-06 09:59:02 · 1241 阅读 · 0 评论 -
Leetcode Longest Common Prefix
/** *https://oj.leetcode.com/problems/longest-common-prefix * Write a function to find the longest common prefix string amongst an array of strings. * 问题描述:写一个函数找到一组字符串的最长公共前缀。 * 这个题要明确一个观点,一组原创 2014-10-06 13:22:43 · 1053 阅读 · 0 评论 -
Leetcode Add two numbers
/*#include using namespace std; *//** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */cla原创 2014-08-22 18:50:25 · 740 阅读 · 0 评论 -
Leetcode Triangle
/*意思就是:给定一个三角形,求得和最小的路径。每层只能选一个整数,上一层和下一层的整数必须是相邻的。思路:1,动态规划。到第i层的第k个顶点的最小路径长度表示为f(i,k),则f(i, k) = min{f(i-1,k), f(i-1,k-1)} + d(i, k); 其中d(i, k)表示原来三角形数组里 的第i行第k列的元素。则可以求得从第一行到最终到第length-1行第原创 2014-10-05 20:29:10 · 904 阅读 · 0 评论