- 博客(50)
- 资源 (1)
- 收藏
- 关注
原创 eclipse快捷键
删除当前光标所在行:ctr+d 移动当前光标所在行:alt+上或者下方向键 自动调整代码格式:ctr+shift+f 自动导入包:ctr+shift+o 多用快捷键提高效率。
2016-09-25 11:48:02
264
原创 leetcode_Number of Islands_medium--dfs
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu
2016-02-22 11:13:59
377
原创 leetcode_Maximum Product Subarray _medium(最大子数组之积)
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges
2015-09-05 22:52:15
391
原创 leetcode_Maximum Subarray _medium(最大子数组的和)
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha
2015-09-05 10:58:30
891
原创 leetcode_Unique Binary Search Trees_easy
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \
2015-09-05 09:51:05
367
原创 leetcode_Valid Anagram_easy
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may a
2015-08-08 20:56:50
478
原创 用栈实现队列-用队列实现栈
用栈实现队列leetcode :Implement Queue using Stacks Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element
2015-08-02 15:40:23
791
原创 leetcode_Power of Two_easy
Given an integer, write a function to determine if it is a power of two.题目意思:判断某个数是否是2的幂。方法:直接进行bit运算,判断是否这个数二进制位里有且仅有一个1。class Solution {public: bool isPowerOfTwo(int n) { int c=0;
2015-07-31 00:06:02
534
原创 leetcode_Rectangle Area _easy
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota
2015-06-24 19:39:15
489
原创 leetcode_Factorial Trailing Zeroes_easy
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.方法:找1...n中每个数因式分解中,5的个数(5的个数一般大于2的个数),即为10的个数注意:题目要求时间复杂度:
2015-06-09 15:38:23
541
原创 leetcode_Isomorphic Strings _easy
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot
2015-06-03 09:53:11
578
原创 leetcode_Reverse Bits_easy
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101
2015-06-02 20:18:52
491
原创 leetcode_Number of 1 Bits_easy
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 00000000
2015-06-02 20:10:38
684
原创 leetcode_Contains Duplicate II_easy
Given an array of integers and an integer k, find out whether there there are two distinct indicesi and j in the array such that nums[i] = nums[j] and the difference betweeni and j is at most k.
2015-06-01 09:47:14
569
原创 leetcode_Contains Duplicate_easy
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is
2015-06-01 09:17:51
569
原创 android好用模拟器genymotion安装过程
折腾了一下,也参考了慕课网里边的课程和网上经验如http://jingyan.baidu.com/article/9faa72315041d8473c28cbc3.html,终于将好用的genymotion模拟器安装好了: 但是需要注意的是:1.安装eclipse插件可能要fq
2015-05-31 10:10:42
498
原创 leetcode_Majority Element (找出现次数大于一半的元素)-easy
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element
2015-03-02 23:30:00
454
原创 友元函数 2个类 定义顺序问题
看c++ primer 友元的部分的时候,p397,遇到这样的问题,就是类A 以另一个类B的成员函数F作为友元,但是这个成员函数F又用到了类A的私有变量,这个问题主要是怎么写类的相关代码的顺序来解决可能遇到的编译不通过的问题。代码如下:#include using namespace std;class Screen;//为了relocate中的形参声明能通过class Wi
2015-03-02 10:16:40
1208
原创 leetcode_Sum Root to Leaf Numbers _DFS_中等难度
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota
2015-02-06 21:36:04
401
原创 leetcode_Permutations II _hard_暴力枚举法--回溯法
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].
2015-02-04 20:02:18
437
原创 leetcode_Binary Tree Level Order Traversal _easy
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20
2015-02-01 21:53:36
2574
原创 leetcode_Valid Sudoku and Sudoku Solver (数独游戏) _easy
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille
2015-01-31 15:48:09
409
原创 八皇后问题--递归调用
参考了算法竞赛入门经典那本书p125:#include const int n=4;int tol=0;int arr[n];//输出某个解void print_res(int arr[],int n){ for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(arr[i]==j) printf(
2015-01-31 12:00:46
386
原创 leetcode_Merge Two Sorted Lists _简单
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.题目就是合并两个有序的链表,具体方法就是:直接操作两个链表的各个指针域,使得最后两个链表连成一个有
2015-01-31 10:36:35
409
原创 leetcode_Symmetric Tree_判断二叉树镜像对称_easy_方法
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti
2015-01-28 16:09:33
586
原创 bfs(队列实现)_dfs(递归以及显式栈实现)
下面是算法竞赛入门经典上p107那道题目的dfs的实现(dfs()函数直接使用递归,dfsSTACK()使用的显式栈)#include #include #define MAXN 100int mat[MAXN][MAXN],vis[MAXN][MAXN];char str[MAXN];typedef struct{int x;int y;}mypoint;mypoint s
2015-01-28 11:11:43
1952
原创 leetcode_Intersection of Two Linked Lists_easy_主要是方法
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2015-01-27 10:56:26
372
原创 leetcode_Roman to Integer_easy_可以看看方法
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.主要弄清楚罗马数字的表示方法:I - 1II- 2III-3IV-4V - 5X - 10L - 50
2015-01-21 21:37:20
457
原创 leetcode_Longest Common Prefix_easy
Write a function to find the longest common prefix string amongst an array of strings.直接进行扫描即可。class Solution {public: string longestCommonPrefix(vector &strs) { int findFlag=0,po
2015-01-21 20:53:52
428
原创 leetcode_length of last word_easy
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is
2015-01-21 19:42:57
364
原创 leetcode_same tree_easy
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.直接递归调用判断就好
2015-01-14 23:13:11
369
原创 leetcode_题解_Palindrome Number _easy_回文数(空间O(1))
题目:判断是否是回文数(空间要求不能用额外的)注意:负数不是回文数class Solution {public: bool isPalindrome(int x) { if(x<0) return false; int tmp=x,res=0; while(tmp) {
2015-01-10 13:53:42
449
原创 数据结构---线性表链式实现
主要参考的严老师那本教材上的:写的比较快,可能代码的可读性不是很好。//带头结点的单链表#include #include #define ElemType inttypedef struct node{ ElemType data; struct node *next;}node;//用data来初始化并分配内存,返回一个新节点node *newNode(ElemT
2015-01-08 10:15:21
356
原创 leetcode_题解_Minimum Depth of Binary Tree _easy需细心
参考了leetcode题解那本书的:需要注意:和max depth稍不同,这里注意叶子节点的概念,不要弄错了。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNo
2015-01-08 10:10:20
343
原创 leetcode_题解_Maximum Depth of Binary Tree_简单题
递归函数调用DFS(没有用显式栈,居然AC了)/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NU
2015-01-08 09:12:35
435
原创 数据结构--线性表顺序实现
主要参考严老师那边教材上的实现的:#include #include #define LIST_INIT_SIZE 100//线性表存储空间初始分配量#define LISTINCREMENT 10//空间不够时,增量分配#define ElemType inttypedef struct{ ElemType *elem;//当前分配的存储空间基址 int length;/
2015-01-06 13:49:01
368
原创 leetcode_题解_path sum 2
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \
2014-11-19 10:15:30
436
原创 leetcode_题解_path sum_easy
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum
2014-11-19 09:15:43
391
原创 leetcode_题解_single number_小技巧
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext
2014-11-18 17:09:42
324
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人