![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
whbing1472
这个作者很懒,什么都没留下…
展开
-
383. Ransom Note
public static boolean canConstruct(String ransomNote, String magazine) { boolean usedFlag[] = new boolean[magazine.length()]; int i = 0,j = 0; for(i = 0;i <ransomNote.length();原创 2016-09-14 16:05:39 · 161 阅读 · 0 评论 -
345. Reverse Vowels of a String
public static String reverseVowels(String s) { String vowels = "aeiouAEIOU"; char[] tmp = s.toCharArray(); int i = 0, j = s.length() -1; while(i < j) { whil原创 2016-09-14 16:33:03 · 175 阅读 · 0 评论 -
344. Reverse String
public static String reverseString(String s) { char[] tmp = s.toCharArray(); int i = 0, j = s.length() -1; while(i < j) { char tmpChar = tmp[i]; tmp[i]原创 2016-09-14 16:40:12 · 299 阅读 · 0 评论 -
349. Intersection of Two Arrays
public static int[] intersection(int[] nums1, int[] nums2) { int[] shortI = nums1; int[] longI = nums2; if(shortI.length > longI.length) { shortI = nums2;原创 2016-09-19 14:31:43 · 178 阅读 · 0 评论 -
1. Two Sum
public static int[] twoSum(int[] nums, int target) { int len = nums.length; int result[] = new int[2]; for(int i = 0; i < len; i++) { for(int j = i+1; j < len; j++)原创 2016-09-19 15:25:35 · 189 阅读 · 0 评论 -
2. Add Two Numbers
public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode ls1 = l1; ListNode ls2 = l2; ListNode result = null,head = null; int process = 0; int va原创 2016-09-19 21:14:07 · 175 阅读 · 0 评论 -
6. ZigZag Conversion
public static String convert(String s, int numRows) { if(numRows == 1) { return s; } int len = s.length(); int zigCount = 0; int zigLen = 2 * numRows原创 2016-10-09 10:46:19 · 163 阅读 · 0 评论 -
7. Reverse Integer
public static int reverse(int x) { boolean isPositive = true; double temDou = 0.0; if(x < 0) { isPositive = false; temDou = Integer.MAX_VALUE *1.0 +原创 2016-10-09 11:43:11 · 175 阅读 · 0 评论 -
8. String to Integer (atoi)
public static int myAtoi(String str) { if(str == null || str.length() < 1) { return 0; } int len = str.length(); double maxDou = 0; boolean isPositive原创 2016-10-09 15:44:23 · 288 阅读 · 0 评论 -
Palindrome Number
public static boolean isPalindrome(int x) { int len = 0; int tmp = x; int i = 0; if(x < 0) { return false; } while(tmp != 0) { len++;原创 2016-10-09 16:54:14 · 130 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
public int lengthOfLongestSubstring(String s) { if(s.length() == 0) { return 0; } int[] flag = new int[128]; int len = s.length(); int i = 0, j = 0;原创 2016-09-21 20:09:35 · 152 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
int allLen = nums1.length + nums2.length; int[] tmp = new int[allLen]; int i = 0,j = 0; double result = 0.0; int len1 = nums1.length, len2 = nums2.length; int co原创 2016-09-21 21:43:32 · 172 阅读 · 0 评论 -
331. Verify Preorder Serialization of a Binary Tree
public static boolean isValidSerialization(String preorder) { if(preorder == null || preorder.length() == 0) { return false; }else { Stack<String> stack = new St原创 2016-11-02 22:45:30 · 133 阅读 · 0 评论 -
58. Length of Last Word
public static int lengthOfLastWord(String s) { if(s == null || s.length() == 0) { return 0; } String[] str= s.split(" "); int i = 0; int len = 0;原创 2016-10-22 21:23:32 · 179 阅读 · 0 评论 -
61. Rotate List
public static ListNode rotateRight(ListNode head, int k) { if(head == null || k <= 0) { return head; } ListNode prep = null, pre = null, cur = head, lastcur = null,c原创 2016-10-22 23:02:34 · 157 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
public static ListNode deleteDuplicates(ListNode head) { if(head == null) { return head; } ListNode thead = head,tcur = head,cur = head; while(cur != null) {原创 2016-10-23 14:17:50 · 159 阅读 · 0 评论 -
86. Partition List
public static ListNode partition(ListNode head, int x) { if(head == null) { return head; } ListNode mhead = null,shead = null,scur =null, mcur = null,cur = head;原创 2016-10-23 14:49:49 · 165 阅读 · 0 评论 -
92. Reverse Linked List II
public static ListNode reverseBetween(ListNode head, int m, int n) { if(head == null | m < 1 || n < 1 || m >= n ) { return head; } int count = 0; ListNode prep = n原创 2016-10-23 15:24:03 · 298 阅读 · 0 评论 -
141. Linked List Cycle
public boolean hasCycle(ListNode head) { if(head == null || head.next == null) { return false; }else if(head.next == head) { return true; } ListN原创 2016-10-24 17:28:08 · 147 阅读 · 0 评论 -
142. Linked List Cycle II
public static ListNode detectCycle(ListNode head) { if(head == null) { return null; }else if(head.next == head) { return head; }else{ ListNod原创 2016-10-24 22:25:50 · 147 阅读 · 0 评论 -
143. Reorder List
public static void reorderList(ListNode head) { if(head == null) { return; } int count = 0; ListNode cur = head; while(cur != null) { cou原创 2016-10-25 10:35:55 · 184 阅读 · 0 评论 -
147. Insertion Sort List
public static ListNode insertionSortList(ListNode head) { if(head == null) { return null; } ListNode cur = head.next,thead = head,tcur =head, tn =nul原创 2016-10-25 11:33:00 · 145 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
public static ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA == null || headB == null) { return null; } ListNode curA = headA,curB = headB;原创 2016-10-25 14:54:08 · 146 阅读 · 0 评论 -
203. Remove Linked List Elements
public static ListNode removeElements(ListNode head, int val) { if(head == null) { return null; } ListNode pre = null, cur = head; while(cur != null) {原创 2016-10-25 15:26:02 · 126 阅读 · 0 评论 -
206. Reverse Linked List
public static ListNode reverseList(ListNode head) { if(head == null ) { return null; } ListNode pre = head, cur = head.next, tn = null; p原创 2016-10-25 15:32:37 · 112 阅读 · 0 评论 -
234. Palindrome Linked List
public static boolean isPalindrome(ListNode head) { if((head == null) || (head!=null && head.next == null)) { return true; } int count = 0; ListNode cur = he原创 2016-10-25 16:04:30 · 199 阅读 · 0 评论 -
237. Delete Node in a Linked List
public static void deleteNode(ListNode node) { if(node == null || node.next == null) { return; } ListNode tn = node.next; node.val = tn.val; node.nex原创 2016-10-25 16:15:08 · 131 阅读 · 0 评论 -
328. Odd Even Linked List
public static ListNode oddEvenList(ListNode head) { if((head == null) || (head != null && head.next == null)){ return head; } ListNode cur = head.next.next,odd = hea原创 2016-10-25 16:31:20 · 134 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
public static ListNode deleteDuplicates(ListNode head) { if(head == null || (head != null && head.next == null)){ return head; } ListNode cur = head.next, thead = he原创 2016-10-25 17:01:53 · 131 阅读 · 0 评论 -
24. Swap Nodes in Pairs
public static ListNode swapPairs(ListNode head) { ListNode pre = null, cur =null; if(head == null){ return head; }else { pre = head; cur = he原创 2016-10-15 15:38:11 · 141 阅读 · 0 评论 -
50. Pow(x, n)
public static double myPow(double x, int n) { double r = 1.0; boolean isOdd = (n % 2 == 0) ? true: false; if(x == 1.0) { return 1.0; } if(x ==原创 2016-10-16 15:17:33 · 336 阅读 · 0 评论 -
14. Longest Common Prefix
public static String longestCommonPrefix(String[] strs) { if(strs == null || strs.length == 0) { return ""; } int strLen = strs.length; String resStr = "";原创 2016-10-16 15:49:39 · 172 阅读 · 0 评论 -
19. Remove Nth Node From End of List
public static ListNode removeNthFromEnd(ListNode head, int n) { if(head == null) { return null; } ListNode predel = null,del = null, cur =head; int count = 0原创 2016-10-16 16:21:25 · 191 阅读 · 0 评论 -
27. Remove Element
public static int removeElement(int[] nums, int val) { if(nums == null || nums.length == 0) { return 0; } int count = 0; int len = nums.length; for(i原创 2016-10-16 16:51:58 · 139 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number
public static List<String> letterCombinations(String digits) { List<String> list1 = new ArrayList<String>(); List<String> list2 = new ArrayList<String>(); List<String> list = li原创 2016-10-16 19:18:24 · 202 阅读 · 0 评论 -
20. Valid Parentheses
public static boolean isValid(String s) { int len = s.length(); char[] stack = new char[s.length()]; int top = -1; int i = 0; for(i = 0; i < len; i++) {原创 2016-10-17 09:21:30 · 141 阅读 · 0 评论 -
21. Merge Two Sorted Lists
public static ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode head= null, cur = null; while(l1!=null && l2!=null) { if(l1.val > l2.val) { if(head原创 2016-10-17 09:40:50 · 145 阅读 · 0 评论 -
25. Reverse Nodes in k-Group
public static ListNode reverseKGroup(ListNode head, int k) { int[] a = new int[k]; int count = 0; ListNode pre = head, cur = head; while(cur != null) { a[cou原创 2016-10-17 10:24:08 · 195 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
public static int removeDuplicates(int[] nums) { int count = 0; for(int i = 0; i < nums.length; i++) { if(i == 0) { nums[count++] = nums[i]; }els原创 2016-10-17 10:34:48 · 183 阅读 · 0 评论 -
28. Implement strStr()
public static int strStr(String haystack, String needle) { if(haystack == null || needle == null) { return -1; } int hLen = haystack.length(); int nLen = nee原创 2016-10-17 10:56:41 · 129 阅读 · 0 评论