This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LRUCache { | |
| public class ListNode { | |
| int val; | |
| int key; | |
| ListNode next; | |
| ListNode prev; | |
| ListNode(int key, int val) { | |
| this.val = val; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Definition for a binary tree node. | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int numIslands(char[][] grid) { | |
| int c = 0; | |
| for (int j = 0; j < grid.length; j++) { | |
| for (int i = 0; i < grid[j].length; i++) { | |
| if (grid[j][i] == '1') { | |
| c++; | |
| findPath(grid, j, i); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Definition for a binary tree node. | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public List<List<String>> groupAnagrams(String[] strs) { | |
| Map<String, List<String>> groups = new HashMap<>(); | |
| for (int i = 0; i < strs.length; i++) { | |
| char[] word = strs[i].toCharArray(); | |
| Arrays.sort(word); | |
| String newWord = String.valueOf(word); | |
| if (groups.containsKey(newWord)){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int countElements(int[] arr) { | |
| if (arr == null) { | |
| return 0; | |
| } | |
| Set<Integer> uniqueElements = new HashSet<>(); | |
| for (int element : arr) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int maxProfit(int[] prices) { | |
| int maxProfit = 0; | |
| int low = 0; | |
| int max = 0; | |
| for (int i = 1; i < prices.length; i++) { | |
| if (max == 0 && prices[i - 1] < prices[i]) { | |
| low = prices[i - 1]; | |
| } | |
| if (low >= 0 && prices[i - 1] < prices[i]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public void moveZeroes(int[] nums) { | |
| int y = 0; | |
| for (int i = 0; i < nums.length; i++) { | |
| if (nums[i] != 0) { | |
| nums[y] = nums[i]; | |
| y++; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public boolean isHappy(int n) { | |
| Set<Integer> set = new HashSet<>(); | |
| while (true) { | |
| int sum = 0; | |
| while (n > 0) { | |
| sum = sum + (n % 10) * (n % 10); | |
| n = n / 10; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int singleNumber(int[] nums) { | |
| if (nums == null || nums.length == 0) return 0; | |
| int single = 0; | |
| for (int i = 0; i < nums.length; i++) single ^= nums[i]; | |
| return single; | |
NewerOlder