![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 51
XiejunNi_技术博客
algorithm && engineering
展开
-
leetcode word search
class Solution { public: bool exist(vector>& board, string word) { if(board.size()==0) return false; if(word.length()==0) return false; vector> visited(board.size(),vector(原创 2015-09-04 21:22:48 · 293 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 比较自然地想到以下三种方法,设k个链表 每个链表n个元素。 1.暴力法 每次遍历k个表头找出最小的元素,O(k),共O(nk)个元素 总复杂度O(nk^2) 2.分治法 两两合并原创 2015-08-18 21:37:16 · 249 阅读 · 0 评论 -
leetcode house Rubber II
Note: This is an extension of House Robber. After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time原创 2015-05-21 14:33:26 · 438 阅读 · 0 评论 -
leetcode Word Break II
class Solution { public: vector wordBreak(string s, unordered_set& wordDict) { //若i-j之间的字符串为字典某一单词 则令矩阵a[i][j]=1,获得可达图 进行深度优先搜索即可。 vector vs; bool a[1000][1000]={{0}}; bool dp[1000]原创 2015-05-19 10:36:34 · 310 阅读 · 0 评论 -
leetcode Search in Rotated Sorted Array
class Solution { public: int search(vector& nums, int target) { if(nums.size()==1){if(target==nums[0]) return 0;else return -1;} if(nums.size()==2){if(target==nums[0]) return 0;els原创 2015-05-12 20:15:25 · 253 阅读 · 0 评论 -
[LeetCode]Longest Common Prefix
class Solution { public: string longestCommonPrefix(vector& strs) { //我的思路是 公共前缀子串 每个字符串都有 先获得1 2的公共子串 然后在拿公共子串 if(strs.size()==0){return "";} if(strs.size()==1){return str原创 2015-05-09 22:33:04 · 358 阅读 · 0 评论 -
两道面试算法题
最近面试 两道算法题 说难不难 要写全对也不容易 很惭愧 第一道:无序int数组 找到中位数void swap(int &a,int &b){ int temp = a ; a = b; b = temp; }int get_kth_number(vector<int> &num,int k,int start,int end){ //类似于快排的一次划分原创 2017-04-19 19:06:54 · 355 阅读 · 0 评论