|
|
摘要:int search(int d[N][N], int key) { int i1, i2, j1, j2; i1 = j1 = 0; i2 = j2 = N-1; while(i1 < i2 && j1 < j2){ if(d[i1][j2] == key) return 1; if(d[i1][j2] < key)...
阅读全文
摘要:public static int MSA(int[] ar) { int[] arr = new int[ar.length]; int msa = 0; arr[0] = ar[0]; for (int i = 1; i = 0) arr[i] = arr[i - 1] + ar[i]; else arr[i] = ar[i]; } for (i...
阅读全文
摘要:public static int LIS(List al) { int[] arr = new int[al.size()]; int lis = 0; arr[0] = 1; for (int i = 1; i al.get(i - 1)) arr[i] = arr[i - 1] + 1; else arr[i] = 1; } for (in...
阅读全文
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3,
阅读全文
摘要:public void reverse (){ Node end =null,p,q; p=head; //p代表当前节点,end代表翻转后p后面的,q代表翻转前p后面的 while(p!=null){ //如果当前节点不为空 q=p.next; //q赋值为p后面的节点 p.next=end; /
阅读全文
摘要:Implement pow(x, n). double sum = 1; if (n > 0) { while ((n--) > 0) sum *= x; return sum; } else if (n < 0) { while ((n++) < 0) sum /= x; } return sum
阅读全文
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ...
阅读全文
摘要:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for a...
阅读全文
摘要: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./** * Def...
阅读全文
摘要:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After ...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings.Subscribe to see which companies asked this question }public cl...
阅读全文
摘要:/* Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes?...
阅读全文
摘要:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are s...
阅读全文
摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRang...
阅读全文
摘要:/*Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?*/public clas...
阅读全文
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the...
阅读全文
摘要:/*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 ...
阅读全文
摘要://Given an integer, write a function to determine if it is a power of two.public class isPowerOfTwo { public static boolean isPowerOfTwo(int n) { ...
阅读全文
摘要:注意:1.怎么至返回一次 2.循环里使用al.remove,al.size()也会变/*Given an array of integers, find two numbers such that they add up to a specific target number.The func...
阅读全文
|