- 博客(8)
- 收藏
- 关注
原创 用异或交换两个变量的值
public static void main(String[] args) { int b=99; int a=10; System.out.println("a="+a); System.out.println("b="+b); a=a^b;//^异或 b=a^b; a=a^b; System.out.println("a="+a); System.out.println("b="+b); }
2020-08-19 09:37:08 149
原创 剑指 Offer 06. 从尾到头打印链表,栈Stack用法(Stack大小,Stack内的类型)
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public int[] reversePrint(ListNode head) { Stack s=new Stack();
2020-08-13 16:52:52 81
原创 剑指 Offer 05. 替换空格,char数组转String,String转char
class Solution { public String replaceSpace(String s) { int len=s.length();//String长度 char []a=new char[len*3];//3倍长度确保够用 int j=0;//j为新数组下标 for(int i=0;i<len;i++){ char c=s.charAt(i);//String转char
2020-08-13 15:13:28 95
原创 课后作业2-two-sum,暴力枚举
import java.util.*; public class Solution { /** * @param numbers int整型一维数组 * @param target int整型 * @return int整型一维数组 */ public int[] twoSum (int[] numbers, int target) { int len=numbers.length;//获取数组长度 int a[
2020-08-12 12:11:55 86
原创 JavaHashMap用法
HashMap<String , Integer> map = new HashMap<>(); map.put("a",1);//增 map.remove("a");//删 map.put("a",2);//改 map.containsKey("zuo");//查(是否存在)
2020-08-12 10:25:58 253
原创 回文链表,用栈解题
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public boolean isPalindrome(ListNode A) { Stack s=new Stack();
2020-08-12 10:19:10 171
原创 HashSet用法,获取数组长度,剑指 Offer 03. 数组中重复的数字
import java.util.*; class Solution { public int findRepeatNumber(int[] nums) { HashSet<Integer> hm=new HashSet<>(); int len=nums.length; for(int i=0;i<len;i++){ if(!hm.contains(nums[i])){//nums[i]是
2020-08-12 10:15:27 569
原创 Java栈Stack用法
import java.util.* Stack s=new Stack(); s.push(p.val); s.empty() while(!s.empty()) s.pop();
2020-08-12 10:09:52 116
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人