自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 收藏
  • 关注

原创 2. Add Two Numbers

题目:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and

2017-04-29 22:17:12 118

原创 496. Next Greater Element I

public class Solution { public int[] nextGreaterElement(int[] nums1, int[] nums2) { int len1 = nums1.length; int len2 = nums2.length; int[] ans = new int[len1]; Arr

2017-04-29 10:35:32 118

原创 225. Implement Stack using Queues

Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet

2017-04-28 11:18:17 134

原创 162. Find Peak Element 再做一遍!

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in

2017-04-25 22:06:44 128

原创 240. Search a 2D Matrix II && 74. Search a 2D Matrix

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in

2017-04-25 20:39:30 166

原创 436. Find Right Interval 要重新做!!

题目:Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i, which can be called tha

2017-04-15 18:55:07 196

原创 454. 4Sum II

题目:Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D ha

2017-04-15 18:45:21 116

原创 287. Find the Duplicate Number

题目:Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate n

2017-04-15 18:43:43 98

原创 349. Intersection of Two Arrays & 350. Intersection of Two Arrays II

349的题目要求:Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be

2017-04-12 09:49:56 134

原创 278. First Bad Version

题目:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed

2017-04-10 23:55:14 117

原创 69. Sqrt(x)----binary search

mplement int sqrt(int x).Compute and return the square root of x.题目就是要实现平方根的功能,但是要注意!!!当输入的数字不是完全平方数的时候需要返回距离它最下的完全平方数的平方根比如当为7的时候,返回2改了好几遍代码,注意了要把输入的数字变成long最后成功的是因为改了跳出循环的判断,跳出循环是因为left>

2017-04-10 20:37:47 385

原创 374. Guess Number Higher or Lower---------binary search

题目是:We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the n

2017-04-10 19:58:54 142

原创 167. Two Sum II - Input array is sorted-----binary search

题目如下:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the

2017-04-10 15:40:03 242

原创 367. Valid Perfect Square

题目:Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16

2017-04-09 22:42:07 154

原创 61. Rotate List 再做一次

Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL./** * Definition for singly-linked

2017-04-09 17:50:09 155

原创 160. Intersection of Two Linked Lists 要再做一遍

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public

2017-04-07 19:15:05 150

原创 21. 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.Subscribe to see which companies asked this questio

2017-04-07 11:26:02 106

原创 234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?/** * Definition for singly-linked list. * public class ListNode { *

2017-04-06 22:29:33 259

原创 445. Add Two Numbers II 不会写理解了答案

public class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { Stack s1 = new Stack(); Stack s2 = new Stack(); //push all value into stack while(

2017-04-05 22:44:18 336

原创 206.reverse linked list 看了答案会写的

Reverse a singly linked list.将单链表反过来打印是先看的答案然后会写的/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * }

2017-04-04 20:17:13 141

原创 203. Remove Linked List Elements 没做出来

public class Solution { public ListNode removeElements(ListNode head, int val) { ListNode fakehead = new ListNode(-1); fakehead.next=head; ListNode cur = head; List

2017-04-04 08:59:02 124

原创 83 Remove Duplicates from Sorted List

还是linkedlist的题目1---2---2---3---4---4----5 sort list 去重使得result为:1---2---3---4---5/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; *

2017-04-03 23:07:26 162

原创 237. Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value

2017-04-03 16:09:53 135

原创 141. Linked List Cycle 没做出来 看的别人的答案 很巧妙

有linkedlist的相关知识 可以参考:http://blog.csdn.net/jdsjlzx/article/details/41654295判断list里面有没有回路:没做出来 网上有个很nb的做法:'fast' travel two steps per time while 'slow' travel one step per time, if there is a cycle

2017-04-03 14:29:09 193

原创 空间时间复杂度笔记

时间复杂度:O(f(n))简称为时间复杂度,其中的f(n)一般是算法中频度最大的语句频度。常见的算法时间复杂度由小到大依次为:Ο(1)<Ο(log2n)<Ο(n)<Ο(nlog2n)<Ο(n2)<Ο(n3)<…<Ο(2n)<Ο(n!)优---------------------劣1. 关于O(log2n)的求解:i=1;-------

2017-04-02 11:46:59 128

原创 9. Palindrome Number

回文数字判断:12321酱紫 还包括复数我的解法:打败36%..主要是把int--->String---->StringBuffer只有StringBuffer才有reverse()的方法通过把给的数字reverse 然后进行比较 相同则为回文数 true 不同则为false代码如下:public class Solution { public boolean is

2017-04-02 09:28:56 171

原创 HashMap 学习-2

key可以是任何对象比如:Map map = new HashMap();map.put("xdx",new Friend("wzh"));  增加键值对到map里map.put("dxd",new Friend("hzw"));Wife w = (Wife)map.get("xdx");  取出值这个时候w.name的值为wzhclass Wife(){S

2017-04-01 23:18:26 142

原创 7. Reverse String 解题 测试十位数过不了

题目: 123--------321 -123--------- -321public class Solution { public int reverse(int x) { int remain=Math.abs(x%10); String r=String.valueOf(remain); int l=Math.abs(x/10);

2017-04-01 12:46:29 176

转载 HashMap 学习总结

本文参考见:http://www.cnblogs.com/chenssy/p/3521565.html  by: chenssy 知识点:1. HashMap的三个构造函数:HashMap( )    默认初始容量为16, 默认加载因子是0.75HashMap(int initialCapacity) 指定初始容量 但默认加载因子为0.75HashMap(int initi

2017-04-01 08:15:15 212

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除