
LeetCode
文章平均质量分 70
zwfars
这个作者很懒,什么都没留下…
展开
-
LeetCode 290 Word Pattern
最近开始学习C++,然后开始算法题了。好像两年没有做过算法题了。。 题目链接 https://leetcode.com/problems/word-pattern/ 我的方法比较笨,首先将str转化为一个单词组,如果pattern 里面哪两个字符相等,那么单词组的单词也要相等。。 讨论区里大家的算法比较好,是纵向比较。就是一个映射。比如我pattern 里面的a对应的是str的dog原创 2015-10-07 16:51:07 · 426 阅读 · 0 评论 -
Leetcode 524. Longest Word in Dictionary through Deleting
class Solution { public: static bool cmp(const string& s1, const string& s2) { if (s1.size() == s2.size()) return s1 < s2; return s1.size()>s2.size(); } string findLongestWord(string s, vec原创 2017-02-26 15:34:48 · 411 阅读 · 0 评论 -
Leetcode 523. Continuous Subarray Sum
class Solution { public: bool checkSubarraySum(vector& nums, int k) { int len = nums.size(); vector sum(len+5); for(int i= 1;i<=len;i++) sum[i] = sum[i-1] + num原创 2017-02-26 15:33:22 · 611 阅读 · 0 评论 -
Leetcode 530. Minimum Absolute Difference in BST
class Solution { public: int getMinimumDifference(TreeNode* root) { vector tem; dfs(root,tem); int ans; int len = tem.size(); ans = abs(tem[1]-tem[0]);原创 2017-02-26 15:32:14 · 375 阅读 · 0 评论 -
Leetcode Freedom Trail
class Solution { public: int findRotateSteps(string ring, string key) { int lenring = ring.size(); int lenkey = key.size(); vector> dp(200, vector(200, 1000000)); for (int i = 0; i < lenkey;原创 2017-03-05 16:29:52 · 1161 阅读 · 0 评论 -
Leetcode 107. Binary Tree Level Order Traversal II
class Solution { public: vector> levelOrderBottom(TreeNode* root) { vector> ans; if(!root) return ans; queue aux; aux.push(root); while(!aux.emp原创 2017-02-23 20:45:09 · 241 阅读 · 0 评论 -
Leetcode 525. Contiguous Array
class Solution { public: int findMaxLength(vector& nums) { int len = nums.size(); unordered_map aux; aux[0] = -1; int cnt = 0; int ans = 0; for(int原创 2017-02-22 20:00:47 · 564 阅读 · 0 评论 -
Leetcode Beautiful Arrangement
class Solution { public: int countArrangement(int N) { vector test(N+5,0); for (int i = 1; i <= N; i++) test[i] = i; int ans = 0; vector> ansvec; vector> avec; create(test, 1, N, ans);原创 2017-02-19 14:43:30 · 742 阅读 · 0 评论 -
leetcode 232. Implement Queue using Stacks
class MyQueue { public: /** Initialize your data structure here. */ stack pstack; stack auxstack; MyQueue() { } /** Push element x to the back of queue. */ void push(i原创 2017-02-17 20:01:20 · 402 阅读 · 0 评论 -
Leetcode 122. Best Time to Buy and Sell Stock II
class Solution { public: int maxProfit(vector& prices) { int len = prices.size(); if(!len) return 0; vector dp(len+5); for(int i=1;i<len;i++)原创 2017-02-16 21:39:17 · 206 阅读 · 0 评论 -
Leetcode 529. Minesweeper
class Solution { public: vector> updateBoard(vector>& board, vector& click) { int x = click[0]; int y = click[1]; int high = board.size(); int len = board[0].size(); vector> ans(board); i原创 2017-02-26 15:35:53 · 683 阅读 · 0 评论