自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(20)
  • 收藏
  • 关注

原创 C语言之C语颂

歌颂C语言

2023-05-15 18:37:07 66

原创 算法概论 8.3

8.3 证明STINGY SAT是一个NP完全问题。要证明一个问题是NP完全问题,首先要证明它是NP的。显然,我们能在多项式时间内验证该问题的一组解,故STINGY SAT是NP的。然后证明它是NP-hard的,我们可以将SAT问题归约到STINGY SAT问题来证明。假设I是SAT的一个实例,若I的变量总数为k,则(I, k)是STINGY SAT问题的一个实例。给定(I, k)的一个解...

2017-07-04 14:41:59 158

原创 165. Compare Version Numbers

class Solution {public: int compareVersion(string version1, string version2) { int v1, v2, t; string s1, s2; v1 = version1.find('.'); v2 = version2.find('.'); ...

2017-06-26 14:50:00 139

原创 416. Partition Equal Subset Sum

class Solution {public: bool canPartition(vector<int>& nums) { int i, j, sum = 0; for(i = 0; i < nums.size(); i++) sum = sum + nums[i]; if(sum % 2 ==...

2017-06-20 16:01:35 126

原创 386. Lexicographical Numbers

class Solution {public: vector<int> lexicalOrder(int n) { vector<int> v(n, 0); int i ,t; v[0] = 1; for(i = 1; i < n; ++i) { if(...

2017-06-10 21:44:56 104

原创 179. Largest Number

bool compare(string a, string b){ string ab(a+b); string ba(b+a); return ab > ba;}class Solution {public: string largestNumber(vector<int>& nums) { string s ...

2017-06-05 00:14:37 108

原创 15. 3Sum

class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { sort(nums.begin(), nums.end()); vector<vector<int>> vec; int i...

2017-05-31 02:34:41 127

原创 309. Best Time to Buy and Sell Stock with Cooldown

class Solution {public: int maxProfit(vector<int>& prices) { int n = prices.size(), i; if(n == 0) return 0; vector<int> buy(n, 0); vector&...

2017-05-20 15:48:02 172

原创 421. Maximum XOR of Two Numbers in an Array

class Solution {public: int findMaximumXOR(vector<int>& nums) { int n = nums.size(), i, j, temp, m = 0, max = 0; for(i = 31; i >= 0; --i) { m = m...

2017-05-14 17:27:11 101

原创 8. String to Integer (atoi)

class Solution {public: int myAtoi(string str) { int i = 0, c = 0; double sum = 0; if(str.size() == 0) return 0; if(str[0] == '+' || str[0] == '-' || str[...

2017-05-08 10:40:05 83

原创 54. Spiral Matrix

class Solution {public: vector<int> spiralOrder(vector<vector<int>>& matrix) { vector<int> spiral; if(matrix.size() == 0) return spiral; ...

2017-05-02 11:27:56 140

原创 3. Longest Substring Without Repeating Characters

class Solution {public: int lengthOfLongestSubstring(string s) { int array[128]; memset(array, -1, sizeof(array)); int i = 0, j = 0, longest = 0; while(i < s.l...

2017-04-24 12:51:51 133

原创 16. 3Sum Closest

class Solution {public: int threeSumClosest(vector<int>& nums, int target) { sort(nums.begin(), nums.end()); int i, n = nums.size(), l, h, sum, min_close = INT_MAX, res...

2017-04-15 17:00:09 168

原创 287.Find the Duplicate Number

O(nlogn):class Solution {public: int findDuplicate(vector<int>& nums) { int n = nums.size(), begin = 1, end = n-1, mid, i, count; while(begin < end) { ...

2017-04-09 17:33:12 92

原创 142. Linked List Cycle II

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *d...

2017-04-01 22:55:06 107

原创 406. Queue Reconstruction by Height

bool compare(pair<int, int> a, pair<int, int> b){ if(a.first > b.first) return 1; else if(a.first == b.first && a.second < b.second) return 1; return 0;...

2017-03-26 15:40:02 125

原创 19. Remove Nth Node From End of List

/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* removeNthFromEnd(struct ListNode* head, int n) { struct Lis...

2017-03-19 21:52:55 97

原创 4. Median of Two Sorted Arrays

class Solution {public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { int n = nums1.size() + nums2.size(), i = 0, j = 0; while(i+j !...

2017-03-11 20:55:56 90

原创 240. Search a 2D Matrix II

class Solution {public: bool searchMatrix(vector<vector<int>>& matrix, int target) { if(matrix.size() == 0 || matrix[0].size() == 0) return false; int row...

2017-03-04 11:12:36 124

原创 1. two sum

class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> answer; map<int, int> mymap; int i = 0, t; map...

2017-02-25 21:55:08 112

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除