LeetCode
文章平均质量分 70
靠靠的博客
好好生活
展开
-
冒泡排序——java
冒泡排序是算法中经典排序方法之一。名字也比较形象,因为整个过程可以看做是一堆泡泡向上飘,最终最轻的泡泡冒出来了(先不说物理规律……),第二趟扫描,“次轻”的泡泡冒上来,以此类推。 冒泡排序规则是 一个数组若有N项,那么会做出N-1 趟排序,才能够得到最终结果。比如数组score【】={3,5,1,8,2} 如按照从小到大的顺序,从左往右,3和5比较5大,不交换;5和1比较5大,则交换1和5的位转载 2013-03-02 22:50:45 · 418 阅读 · 0 评论 -
234. Palindrome Linked List java leetcode
题目:判断一个链表是否是回文就是诸如1-2-3-2-1 1-2-3-3-2-1 奇数个或者偶数个这样的。方法一:快慢指针,前半部分放入栈中,快指针到达结尾,慢指针到达中间,然后慢指针继续后续遍历,和栈中的弹出来一个个比较。若一旦有不同就return false,都一样就最后返回true。方法二:将链表切割为两部分,再将某一部分进行inverse反转链表,再对两个链表挨个比较原创 2016-05-28 15:50:29 · 381 阅读 · 0 评论 -
350. Intersection of Two Arrays II - LeetCode
350. Intersection of Two Arrays IIGiven two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. 用的python:原创 2017-07-10 18:29:44 · 246 阅读 · 0 评论 -
387. First Unique Character in a String - leetcode
387. First Unique Character in a String Given a string, find the first non-repeatingcharacter in it and return it's index. If it doesn't exist, return -1.Examples: s = "leetcode"retu原创 2017-07-11 19:52:56 · 230 阅读 · 0 评论 -
412. Fizz Buzz - leetcode
412. Fizz Buzz - leetcodeWrite a program that outputs the string representation of numbersfrom 1 to n.But for multiples of three it should output “Fizz” instead of thenumber and for the multiples原创 2017-07-12 18:50:21 · 312 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree - leetcode
104.Maximum Depth of Binary Tree Given abinary tree, find its maximum depth.Themaximum depth is the number of nodes along the longest path from the root nodedown to the farthest leaf node.求一原创 2017-07-15 19:25:34 · 220 阅读 · 0 评论 -
leetcode-Total Hamming Distance
先看题意:Input: 4,14, 2 Output: 6 Explanation:In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (justshowingthe four bits relevant in this case). So the answer will be:Hammi原创 2017-07-06 18:36:33 · 249 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal - Leetcode
Leetcode102. Binary Tree Level Order Traversal 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原创 2017-07-20 16:36:00 · 354 阅读 · 0 评论 -
476. Number Complement - leetcode
476.Number ComplementGiven apositive integer, output its complement number. The complement strategy is toflip the bits of its binary representation.Note:The giveninteger is guaranteed to fit w原创 2017-07-07 19:33:29 · 203 阅读 · 0 评论 -
268.Missing Number leetcode
268.Missing NumberGiven anarray containing n distinct numbers taken from 0, 1, 2, ..., n, find the onethat is missing from the array.Forexample,Givennums = [0, 1, 3] return 2.Note:Your原创 2017-07-09 10:20:08 · 230 阅读 · 0 评论 -
202. Happy Number - leetcode
LeetCodeWrite an algorithm to determine if a number is "happy".A happy number is a number defined by the following process:Starting with any positive integer, replace the number by the sum of thes原创 2017-07-17 20:09:59 · 270 阅读 · 0 评论 -
326. Power of Three - leetcode
326. Power of Three Given an integer, write a function to determine if it is a power ofthree. Follow up:Could you do it without using any loop / recursion? 判断一个数是否是3的幂,不适用循环和递归利用对数换底原创 2017-07-09 16:23:10 · 227 阅读 · 0 评论 -
Hamming distance- leetcode
开启leetcode刷题模式今天只做了最简单的 Hamming distanceclass Solution(object): def hammingDistance(self, x, y): """ :type x: int :type y: int :rtype: int resul原创 2017-07-05 18:55:45 · 324 阅读 · 0 评论 -
189. Rotate Array - leetcode
189. Rotate Array Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many原创 2017-07-18 19:55:43 · 319 阅读 · 0 评论 -
125. Valid Palindrome - LeetCode
125. Valid Palindrome Given a string, determine if it is a palindrome, considering onlyalphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palind原创 2017-07-19 18:31:11 · 337 阅读 · 0 评论 -
largest number - leetcode - python
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is9534330.Note: The result may be very原创 2017-08-11 16:22:21 · 499 阅读 · 0 评论 -
20. Valid Parentheses-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】20. Valid Parentheses-leetcode-java发表于 2016/02/05先看题目要求Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if原创 2016-05-06 18:52:21 · 507 阅读 · 0 评论 -
21. Merge Two Sorted Lists-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】21. Merge Two Sorted Lists-leetcode-java发表于 2016/02/05题目Merge two sorted linked lists and return it as a new list. The new list should be made by spl原创 2016-05-06 18:51:52 · 724 阅读 · 0 评论 -
28. Implement strStr()-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】28. Implement strStr()-leetcode-java发表于 2016/02/06题意Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if原创 2016-05-06 18:50:17 · 1798 阅读 · 0 评论 -
【王道九度OJ】1202排序
//1202#includeint main(){int n;int buf[100]; while( scanf("%d", &n) != EOF ) //the main loop start { for(int i=0; i<n; i++) { scanf("%d", &buf[i] ); } for(i原创 2014-08-24 15:35:02 · 1011 阅读 · 0 评论 -
【王道九度OJ】1061成绩排序
王道的第1061 成绩排序 题目原创 2014-08-24 16:42:42 · 1225 阅读 · 0 评论 -
【王道九度OJ】1061日期差值
#include#define isLeapYear(x) x%100 != 0 && x%4 == 0 || x%400 == 0 ? 1 : 0 //使用宏定义是否是闰年//using namespace std;int dayOfMonth[13][2]={ 0,0, 31,31, 28,29, 31,31, 30,30, 31,31, 30,30, 31,31,原创 2014-08-24 18:57:03 · 733 阅读 · 0 评论 -
【王道九度OJ】1043 day of week
运行 提交 总是 wrong answer ,我也不知道哪里错了。隐隐感觉日期换算倒来倒去的原创 2014-08-24 20:57:59 · 1455 阅读 · 0 评论 -
【王道九度OJ】1018 统计同成绩学生人数||hash的应用
本题相对于上一题就很简单了。思路很巧妙 运用hash数组 存放每一个分数的人数,最后直接shuchu原创 2014-08-24 21:24:58 · 908 阅读 · 4 评论 -
leetcode118 and 119 Pascal's Triangle
题目是Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]网上找到的一个原创 2015-10-02 16:04:40 · 372 阅读 · 0 评论 -
leetcode 283 move zeroes -java
自己的方法好像不合要求,因为开辟了链表空间,还在那儿调的不亦乐乎……public class Solution { public void moveZeroes(int[] nums) { int zero=0; Queue qu = new LinkedList();//思路就是采用了队列,链表,遇到0就计数,不是0就加到队列 for(原创 2015-12-11 10:58:55 · 1103 阅读 · 0 评论 -
判断单链表是否有环以及碰撞点连接点
给定一个单链表,只给出头指针h:1、如何判断是否存在环?2、如何知道环的长度?3、如何找出环的连接点在哪里?4、带环链表的长度是多少?解法:1、对于问题1,使用追赶的方法,设定两个指针slow、fast,从头指针开始,每次分别前进1步、2步。如存在环,则两者相遇;如不存在环,fast遇到NULL退出。2、对于问题2,记录下问题1的碰撞点p,s转载 2016-05-26 11:03:27 · 792 阅读 · 0 评论 -
24. Swap Nodes in Pairs -leetcode-java
今天一下午被这道题困惑好久,也是够笨呀。Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.题意就是交换一个链表每两个相邻节点。publ原创 2016-05-26 18:54:52 · 885 阅读 · 0 评论 -
98. Validate Binary Search Tree-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】98. Validate Binary Search Tree-leetcode-java发表于 2016/02/12题意Given a binary tree, determine if it is a valid binary search tree (BST).判定一棵树是不是二分搜原创 2016-05-06 18:43:22 · 276 阅读 · 0 评论 -
73. Set Matrix Zeroes-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】73. Set Matrix Zeroes-leetcode-java发表于 2016/02/11题目Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.原创 2016-05-06 18:43:47 · 604 阅读 · 0 评论 -
65. Valid Number-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】65. Valid Number-leetcode-java发表于 2016/02/10题目:Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false原创 2016-05-06 18:44:57 · 1589 阅读 · 0 评论 -
57. Insert Interval-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】57. Insert Interval-leetcode-java发表于 2016/02/09题目:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necess原创 2016-05-06 18:45:32 · 774 阅读 · 0 评论 -
56. Merge Intervals-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】56. Merge Intervals-leetcode-java发表于 2016/02/08题意Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6]原创 2016-05-06 18:48:42 · 1043 阅读 · 0 评论 -
50. Pow(x, n)-leetcode-java
【原来在SAE的blog上,都转到CSDN了。。】50. Pow(x, n)-leetcode-java发表于 2016/02/06题目Implement pow(x, n). 实现浮点类型的幂运算, x的n次幂。思路:开始用的递归,感觉应该可以啊,但是报超时了。后来用这种减半的方法,效率上肯定是提高了。开始exp设置成double原创 2016-05-06 18:49:44 · 931 阅读 · 0 评论 -
69. Sqrt(x) leetcode
Implement int sqrt(int x).Compute and return the square root of x.题意很简单,求一个数的开方,这里都是int型的最近一直在上课学R,偷懒没有刷leetcode,隔了这些天手生了,一道easy做了好久,还用的不怎么样的方法,接下来要坚持每天至少一道,又不会太费时间,很想念前些天上洗手间路上都可以思考,这是多原创 2017-08-05 13:40:03 · 413 阅读 · 0 评论