随笔分类 -  LeetCode

leetcode里面的一些解决方案
摘要:class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { set<vector<int>> res; sort(nums.begin(), nums.end()); for (int k = 0; k < n 阅读全文
posted @ 2017-02-07 00:00 王坤1993 阅读(158) 评论(0) 推荐(0)
摘要:class Solution { public: string longestCommonPrefix(vector<string>& strs) { if (strs.empty()) return ""; for (int j = 0; j < strs[0].size(); ++j) { fo 阅读全文
posted @ 2017-02-06 00:06 王坤1993 阅读(124) 评论(0) 推荐(0)
摘要:class Solution { public: int romanToInt(string s) { int res = 0; unordered_map<char, int> m{{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D' 阅读全文
posted @ 2017-02-04 23:38 王坤1993 阅读(122) 评论(0) 推荐(0)
摘要:class Solution { public: string intToRoman(int num) { string res = ""; vector<int> val{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; vector<s 阅读全文
posted @ 2017-02-04 00:17 王坤1993 阅读(173) 评论(0) 推荐(0)
摘要:class Solution { public: bool isMatch(string s, string p) { int m = s.size(), n = p.size(); vector<vector<bool>> dp(m + 1, vector<bool>(n + 1, false)) 阅读全文
posted @ 2017-02-01 21:07 王坤1993 阅读(159) 评论(0) 推荐(0)
摘要:class Solution {public: bool isPalindrome(int x) { //negative number if(x < 0) return false; int len = 1; while(x / len >= 10) len *= 10; while(x > 0) 阅读全文
posted @ 2017-02-01 21:03 王坤1993 阅读(155) 评论(0) 推荐(0)
摘要:public class Solution { public int myAtoi(String str) { if (str.isEmpty()) return 0; int sign = 1, base = 0, i = 0, n = str.length(); while (i < n && 阅读全文
posted @ 2017-02-01 00:26 王坤1993 阅读(184) 评论(0) 推荐(0)
摘要:class Solution { public: int reverse(int x) { int res = 0; while (x != 0) { int t = res * 10 + x % 10; if (t / 10 != res) return 0; res = t; x /= 10; 阅读全文
posted @ 2017-01-30 23:54 王坤1993 阅读(160) 评论(0) 推荐(0)
摘要:class Solution { public: string convert(string s, int nRows) { if (nRows <= 1) return s; string res = ""; int size = 2 * nRows - 2; for (int i = 0; i 阅读全文
posted @ 2017-01-29 20:24 王坤1993 阅读(243) 评论(0) 推荐(0)
摘要:// Time complexity O(n*n) class Solution { public: string longestPalindrome(string s) { int startIdx = 0, left = 0, right = 0, len = 0; for (int i = 0 阅读全文
posted @ 2017-01-29 20:20 王坤1993 阅读(148) 评论(0) 推荐(0)
摘要:class Solution { public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { int total = nums1.size() + nums2.size(); if (total % 阅读全文
posted @ 2017-01-29 20:19 王坤1993 阅读(140) 评论(0) 推荐(0)
摘要:class Solution { public: int lengthOfLongestSubstring(string s) { int m[256] = {0}, res = 0, left = 0; for (int i = 0; i < s.size(); ++i) { if (m[s[i] 阅读全文
posted @ 2017-01-29 20:18 王坤1993 阅读(131) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode dummy = new ListNode(-1); ListNode cur = dummy; int carry = 阅读全文
posted @ 2017-01-26 23:54 王坤1993 阅读(157) 评论(0) 推荐(0)
摘要: public class Solution { public int[] twoSum(int[] numbers, int target) { HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); int[] 阅读全文
posted @ 2017-01-26 00:03 王坤1993 阅读(147) 评论(0) 推荐(0)